File size: 1,960 Bytes
ce4e93d
ab41f33
3b79365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab41f33
 
e6bead9
ab41f33
3b79365
ab41f33
3b79365
 
 
 
 
 
 
 
 
 
ab41f33
3b79365
 
ce4e93d
e6bead9
ab41f33
e6bead9
ab41f33
e6bead9
 
ab41f33
 
e6bead9
 
 
 
 
 
ab41f33
 
e6bead9
3b79365
 
ce4e93d
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
import gradio as gr
from deep_translator import GoogleTranslator
import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer

# Download necessary NLTK data
nltk.download('punkt', quiet=True)
nltk.download('stopwords', quiet=True)
nltk.download('wordnet', quiet=True)

def natural_language_understanding(text):
    tokens = word_tokenize(text.lower())
    stop_words = set(stopwords.words('english'))
    lemmatizer = WordNetLemmatizer()
    processed_tokens = [lemmatizer.lemmatize(token) for token in tokens if token not in stop_words]
    return " ".join(processed_tokens)

def translate_text(text, target_language):
    translator = GoogleTranslator(source='auto', target=target_language)
    return translator.translate(text)

def process_input(input_text, feature, target_language):
    if not input_text:
        return "No input provided"

    processed_text = natural_language_understanding(input_text)

    if feature == "Translation":
        result = translate_text(processed_text, target_language)
    elif feature == "Transcription":
        result = processed_text
    else:
        result = "Invalid feature selected"

    return result

# Create Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("# The Advanced Multi-Faceted Chatbot")
    gr.Markdown("Enter text to interact with the chatbot. Choose a feature and specify language for translation if needed.")
    
    input_text = gr.Textbox(label="Input Text")
    
    with gr.Row():
        feature = gr.Radio(["Translation", "Transcription"], label="Feature")
        target_language = gr.Textbox(label="Target Language (e.g., 'fr' for French)")
    
    submit_button = gr.Button("Process")
    result_text = gr.Textbox(label="Result")

    submit_button.click(
        process_input,
        inputs=[input_text, feature, target_language],
        outputs=result_text
    )

# Launch the interface
demo.launch()