Spaces:
Sleeping
Sleeping
import gradio as gr | |
import wikipedia | |
import openai | |
import os | |
# Define language options for translation | |
LANGUAGES = { | |
"Arabic": "ar", | |
"English": "en", | |
"Spanish": "es", | |
"French": "fr", | |
"German": "de", | |
"Italian": "it", | |
"Portuguese": "pt", | |
"Russian": "ru", | |
"Japanese": "ja", | |
"Chinese": "zh", | |
"Arabic": "ar", | |
"Hindi": "hi", | |
"Korean": "ko" | |
} | |
def extract_wikipedia_content(wiki_url, api_key, model_id, base_url, target_lang): | |
""" | |
Function to extract content from Wikipedia URL (placeholder for now) | |
""" | |
# Will implement the actual extraction and translation later | |
return f"Configuration saved. API Key: {api_key[:5]}..., Model: {model_id}, Target Language: {target_lang}" | |
# Create Gradio app | |
with gr.Blocks(theme=gr.themes.Monochrome()) as app: | |
gr.Markdown("# Wikipedia Translator") | |
with gr.Row(): | |
# Sidebar for configuration | |
with gr.Column(scale=1): | |
gr.Markdown("### Configuration") | |
with gr.Group(): | |
api_key = gr.Textbox( | |
label="OpenAI API Key", | |
placeholder="sk-...", | |
type="password", | |
) | |
model_id = gr.Textbox( | |
label="OpenAI Model ID", | |
placeholder="gpt-4.1-mini", | |
) | |
base_url = gr.Textbox( | |
label="OpenAI API Base URL (Optional)", | |
placeholder="https://api.openai.com/v1", | |
info="Leave default unless using a proxy" | |
) | |
target_language = gr.Dropdown( | |
choices=list(LANGUAGES.keys()), | |
value="Spanish", | |
label="Target Language", | |
) | |
gr.Markdown("### About") | |
gr.Markdown(""" | |
This tool extracts content from Wikipedia articles and translates them into your selected language using OpenAI's language models. | |
1. Configure your API settings | |
2. Enter a Wikipedia URL | |
3. Click Extract to process the article | |
""") | |
# Main content area | |
with gr.Column(scale=2): | |
gr.Markdown("### Wikipedia Article") | |
wiki_url = gr.Textbox( | |
label="Wikipedia URL", | |
placeholder="https://en.wikipedia.org/wiki/Artificial_intelligence", | |
info="Enter the full URL of the Wikipedia article" | |
) | |
extract_button = gr.Button("Extract and Prepare for Translation", variant="primary") | |
output = gr.Textbox(label="Status") | |
# Results area (will expand in the future) | |
article_info = gr.Textbox(label="Article Information", visible=False) | |
article_content = gr.Textbox(label="Article Content", visible=False) | |
# Connect the extract button to the function | |
extract_button.click( | |
fn=extract_wikipedia_content, | |
inputs=[wiki_url, api_key, model_id, base_url, target_language], | |
outputs=[output] | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
app.launch() | |