File size: 3,296 Bytes
ce96e8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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()