Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
sentiment_model = pipeline("sentiment-analysis")
|
5 |
+
chatbot_model = pipeline("text-generation", model="microsoft/DialoGPT-medium")
|
6 |
+
summarization_model = pipeline("summarization")
|
7 |
+
text_to_speech_model = pipeline("text-to-speech")
|
8 |
+
|
9 |
+
def get_sentiment(input_text):
|
10 |
+
analysis = sentiment_model(input_text)
|
11 |
+
sent = analysis[0]['label']
|
12 |
+
score = analysis[0]['score']
|
13 |
+
return sent, score
|
14 |
+
|
15 |
+
def chatbot_response(input_text):
|
16 |
+
response = chatbot_model(input_text, max_length=100, do_sample=True)[0]['generated_text']
|
17 |
+
return response
|
18 |
+
|
19 |
+
def summarize_text(input_text):
|
20 |
+
summary = summarization_model(input_text, max_length=100, min_length=30, do_sample=False)
|
21 |
+
return summary[0]['summary_text']
|
22 |
+
|
23 |
+
def text_to_speech(input_text):
|
24 |
+
audio = text_to_speech_model(input_text)
|
25 |
+
return audio
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
gr.Markdown("## Multi-Function AI Language Application")
|
29 |
+
|
30 |
+
with gr.Tab("Sentiment Analysis"):
|
31 |
+
text_input = gr.Textbox(label="Enter text for sentiment analysis:")
|
32 |
+
sentiment_output = gr.Textbox(label="Sentiment")
|
33 |
+
score_output = gr.Number(label="Confidence Score")
|
34 |
+
sentiment_button = gr.Button("Analyze")
|
35 |
+
sentiment_button.click(get_sentiment, inputs=text_input, outputs=[sentiment_output, score_output])
|
36 |
+
|
37 |
+
with gr.Tab("Chatbot"):
|
38 |
+
chat_input = gr.Textbox(label="Enter your message:")
|
39 |
+
chat_output = gr.Textbox(label="Chatbot Response")
|
40 |
+
chat_button = gr.Button("Send")
|
41 |
+
chat_button.click(chatbot_response, inputs=chat_input, outputs=chat_output)
|
42 |
+
|
43 |
+
with gr.Tab("Summarization"):
|
44 |
+
summary_input = gr.Textbox(label="Enter text to summarize:", lines=5)
|
45 |
+
summary_output = gr.Textbox(label="Summary")
|
46 |
+
summary_button = gr.Button("Summarize")
|
47 |
+
summary_button.click(summarize_text, inputs=summary_input, outputs=summary_output)
|
48 |
+
|
49 |
+
with gr.Tab("Text-to-Speech"):
|
50 |
+
tts_input = gr.Textbox(label="Enter text to convert to speech:")
|
51 |
+
tts_output = gr.Audio(label="Generated Speech")
|
52 |
+
tts_button = gr.Button("Convert")
|
53 |
+
tts_button.click(text_to_speech, inputs=tts_input, outputs=tts_output)
|
54 |
+
|
55 |
+
# Launch the app
|
56 |
+
demo.launch()
|