Spaces:
Running
Running
setup the basic app structure
Browse files- app.py +99 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import wikipedia
|
3 |
+
import openai
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Define language options for translation
|
7 |
+
LANGUAGES = {
|
8 |
+
"Arabic": "ar",
|
9 |
+
"English": "en",
|
10 |
+
"Spanish": "es",
|
11 |
+
"French": "fr",
|
12 |
+
"German": "de",
|
13 |
+
"Italian": "it",
|
14 |
+
"Portuguese": "pt",
|
15 |
+
"Russian": "ru",
|
16 |
+
"Japanese": "ja",
|
17 |
+
"Chinese": "zh",
|
18 |
+
"Arabic": "ar",
|
19 |
+
"Hindi": "hi",
|
20 |
+
"Korean": "ko"
|
21 |
+
}
|
22 |
+
|
23 |
+
def extract_wikipedia_content(wiki_url, api_key, model_id, base_url, target_lang):
|
24 |
+
"""
|
25 |
+
Function to extract content from Wikipedia URL (placeholder for now)
|
26 |
+
"""
|
27 |
+
# Will implement the actual extraction and translation later
|
28 |
+
return f"Configuration saved. API Key: {api_key[:5]}..., Model: {model_id}, Target Language: {target_lang}"
|
29 |
+
|
30 |
+
# Create Gradio app
|
31 |
+
with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
32 |
+
gr.Markdown("# Wikipedia Translator")
|
33 |
+
|
34 |
+
with gr.Row():
|
35 |
+
# Sidebar for configuration
|
36 |
+
with gr.Column(scale=1):
|
37 |
+
gr.Markdown("### Configuration")
|
38 |
+
|
39 |
+
with gr.Group():
|
40 |
+
api_key = gr.Textbox(
|
41 |
+
label="OpenAI API Key",
|
42 |
+
placeholder="sk-...",
|
43 |
+
type="password",
|
44 |
+
)
|
45 |
+
|
46 |
+
model_id = gr.Textbox(
|
47 |
+
label="OpenAI Model ID",
|
48 |
+
placeholder="gpt-4.1-mini",
|
49 |
+
)
|
50 |
+
|
51 |
+
base_url = gr.Textbox(
|
52 |
+
label="OpenAI API Base URL (Optional)",
|
53 |
+
placeholder="https://api.openai.com/v1",
|
54 |
+
info="Leave default unless using a proxy"
|
55 |
+
)
|
56 |
+
|
57 |
+
target_language = gr.Dropdown(
|
58 |
+
choices=list(LANGUAGES.keys()),
|
59 |
+
value="Spanish",
|
60 |
+
label="Target Language",
|
61 |
+
)
|
62 |
+
|
63 |
+
gr.Markdown("### About")
|
64 |
+
gr.Markdown("""
|
65 |
+
This tool extracts content from Wikipedia articles and translates them into your selected language using OpenAI's language models.
|
66 |
+
|
67 |
+
1. Configure your API settings
|
68 |
+
2. Enter a Wikipedia URL
|
69 |
+
3. Click Extract to process the article
|
70 |
+
""")
|
71 |
+
|
72 |
+
# Main content area
|
73 |
+
with gr.Column(scale=2):
|
74 |
+
gr.Markdown("### Wikipedia Article")
|
75 |
+
|
76 |
+
wiki_url = gr.Textbox(
|
77 |
+
label="Wikipedia URL",
|
78 |
+
placeholder="https://en.wikipedia.org/wiki/Artificial_intelligence",
|
79 |
+
info="Enter the full URL of the Wikipedia article"
|
80 |
+
)
|
81 |
+
|
82 |
+
extract_button = gr.Button("Extract and Prepare for Translation", variant="primary")
|
83 |
+
|
84 |
+
output = gr.Textbox(label="Status")
|
85 |
+
|
86 |
+
# Results area (will expand in the future)
|
87 |
+
article_info = gr.Textbox(label="Article Information", visible=False)
|
88 |
+
article_content = gr.Textbox(label="Article Content", visible=False)
|
89 |
+
|
90 |
+
# Connect the extract button to the function
|
91 |
+
extract_button.click(
|
92 |
+
fn=extract_wikipedia_content,
|
93 |
+
inputs=[wiki_url, api_key, model_id, base_url, target_language],
|
94 |
+
outputs=[output]
|
95 |
+
)
|
96 |
+
|
97 |
+
# Launch the app
|
98 |
+
if __name__ == "__main__":
|
99 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==5.29.1
|
2 |
+
wikipedia==1.4.0
|
3 |
+
openai==1.78.1
|