ktopwal commited on
Commit
86cbd68
·
verified ·
1 Parent(s): a5d9aaa

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -60
app.py DELETED
@@ -1,60 +0,0 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
-
4
- # Model 1: sentiment classification
5
- sentiment = pipeline(
6
- "sentiment-analysis",
7
- model="distilbert/distilbert-base-uncased-finetuned-sst-2-english"
8
- )
9
-
10
- # Model 2: instruction-following text generation used for summarization
11
- summarizer = pipeline(
12
- "text-generation",
13
- model="Qwen/Qwen2.5-0.5B-Instruct"
14
- )
15
-
16
- def analyze(text):
17
- if not text or not text.strip():
18
- return "Please enter some text."
19
- result = sentiment(text[:5000])[0]
20
- return f"{result['label']} (confidence: {result['score']:.2%})"
21
-
22
- def summarize(text):
23
- if not text or not text.strip():
24
- return "Please enter some text."
25
- if len(text.split()) < 30:
26
- return "Please enter at least 30 words."
27
-
28
- prompt = (
29
- "Summarize the following text in 2-4 concise sentences. "
30
- "Keep the main points and do not add facts.\n\n"
31
- + text[:4000]
32
- )
33
- result = summarizer(
34
- [{"role": "user", "content": prompt}],
35
- max_new_tokens=120,
36
- do_sample=False,
37
- return_full_text=False
38
- )
39
- generated = result[0]["generated_text"]
40
- if isinstance(generated, list):
41
- return generated[-1].get("content", str(generated[-1]))
42
- return str(generated)
43
-
44
- with gr.Blocks(title="Komal's Multitask AI") as demo:
45
- gr.Markdown("# Komal's Multitask AI\nTwo pretrained NLP models in one app.")
46
-
47
- with gr.Tab("Sentiment Analysis"):
48
- sentiment_input = gr.Textbox(label="Text", lines=4)
49
- sentiment_button = gr.Button("Analyze sentiment")
50
- sentiment_output = gr.Textbox(label="Result")
51
- sentiment_button.click(analyze, inputs=sentiment_input, outputs=sentiment_output)
52
-
53
- with gr.Tab("Text Summarization"):
54
- summary_input = gr.Textbox(label="Text (at least 30 words)", lines=8)
55
- summary_button = gr.Button("Summarize")
56
- summary_output = gr.Textbox(label="Summary", lines=5)
57
- summary_button.click(summarize, inputs=summary_input, outputs=summary_output)
58
-
59
- if __name__ == "__main__":
60
- demo.launch()