ksumhs commited on
Commit
3a300c0
Β·
verified Β·
1 Parent(s): cbdbe66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -20
app.py CHANGED
@@ -3,7 +3,7 @@ from transformers import pipeline
3
  from gtts import gTTS
4
  import tempfile
5
 
6
- # Load models from Hugging Face
7
  sentiment_model = pipeline("sentiment-analysis")
8
  summarizer_model = pipeline("summarization")
9
 
@@ -26,27 +26,29 @@ def text_to_speech(text):
26
  tts.save(fp.name)
27
  return fp.name
28
 
29
- # Build Gradio interface with Tabs
30
  with gr.Blocks() as demo:
31
  gr.Markdown("## πŸ“˜ Homework - Tuwaiq Academy")
32
 
33
- with gr.Tabs():
34
- with gr.TabItem("πŸ” Sentiment Analysis"):
35
- input_sentiment = gr.Textbox(label="Enter your text", lines=6, placeholder="Type your text here...")
36
- output_sentiment = gr.Textbox(label="Sentiment Result")
37
- btn_sentiment = gr.Button("Analyze Sentiment")
38
- btn_sentiment.click(analyze_sentiment, inputs=input_sentiment, outputs=output_sentiment)
39
-
40
- with gr.TabItem("πŸ“ Summarization"):
41
- input_summary = gr.Textbox(label="Enter your text", lines=6, placeholder="Type your text here...")
42
- output_summary = gr.Textbox(label="Summary")
43
- btn_summarize = gr.Button("Summarize")
44
- btn_summarize.click(summarize_text, inputs=input_summary, outputs=output_summary)
45
-
46
- with gr.TabItem("πŸ”Š Text to Speech"):
47
- input_tts = gr.Textbox(label="Enter your text", lines=6, placeholder="Type your text here...")
48
- output_audio = gr.Audio(label="Speech Output", type="filepath")
49
- btn_tts = gr.Button("Convert to Speech")
50
- btn_tts.click(text_to_speech, inputs=input_tts, outputs=output_audio)
 
 
51
 
52
  demo.launch()
 
3
  from gtts import gTTS
4
  import tempfile
5
 
6
+ # Load Hugging Face pipelines
7
  sentiment_model = pipeline("sentiment-analysis")
8
  summarizer_model = pipeline("summarization")
9
 
 
26
  tts.save(fp.name)
27
  return fp.name
28
 
29
+ # Gradio app with separate tabs/pages
30
  with gr.Blocks() as demo:
31
  gr.Markdown("## πŸ“˜ Homework - Tuwaiq Academy")
32
 
33
+ with gr.Tab("πŸ” Sentiment Analysis"):
34
+ gr.Markdown("### Analyze the sentiment of your text")
35
+ input_sent = gr.Textbox(label="Enter your text", lines=6, placeholder="Type something...")
36
+ output_sent = gr.Textbox(label="Sentiment Result")
37
+ btn_sent = gr.Button("Analyze")
38
+ btn_sent.click(analyze_sentiment, inputs=input_sent, outputs=output_sent)
39
+
40
+ with gr.Tab("πŸ“ Summarization"):
41
+ gr.Markdown("### Summarize your text")
42
+ input_sum = gr.Textbox(label="Enter your text", lines=6, placeholder="Paste a paragraph...")
43
+ output_sum = gr.Textbox(label="Summary")
44
+ btn_sum = gr.Button("Summarize")
45
+ btn_sum.click(summarize_text, inputs=input_sum, outputs=output_sum)
46
+
47
+ with gr.Tab("πŸ”Š Text to Speech"):
48
+ gr.Markdown("### Convert text to speech")
49
+ input_tts = gr.Textbox(label="Enter your text", lines=6, placeholder="Text for audio...")
50
+ output_audio = gr.Audio(label="Speech Output", type="filepath")
51
+ btn_tts = gr.Button("Convert")
52
+ btn_tts.click(text_to_speech, inputs=input_tts, outputs=output_audio)
53
 
54
  demo.launch()