frankai98 commited on
Commit
2382fa5
·
verified ·
1 Parent(s): 2feb052

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ # Step 1: Define the sentiment analysis pipeline.
4
+ # Here, we use a text classification model.
5
+ sentiment_pipe = pipeline("text-classification", model="mixedbread-ai/mxbai-rerank-base-v1")
6
+
7
+ # Step 2: Define the text generation pipeline with Gemma.
8
+ gemma_pipe = pipeline("text-generation", model="google/gemma-3-1b-it")
9
+
10
+ # Example input text that we want to analyze.
11
+ text = "I love this new product. It has exceeded my expectations and I feel very happy about it."
12
+
13
+ # Perform sentiment analysis on the text.
14
+ sentiment_result = sentiment_pipe(text)
15
+ print("Sentiment Analysis Result:")
16
+ print(sentiment_result)
17
+
18
+ # Prepare a prompt that includes the original text and the sentiment result.
19
+ # The prompt instructs the Gemma model to generate a detailed summary report.
20
+ prompt = f"""
21
+ Generate a detailed report based on the following analysis.
22
+
23
+ Original text:
24
+ "{text}"
25
+
26
+ Sentiment analysis result:
27
+ {sentiment_result}
28
+
29
+ Please provide a concise summary report explaining the sentiment and key insights.
30
+ """
31
+
32
+ # Use the Gemma pipeline to generate the summary report.
33
+ report = gemma_pipe(prompt, max_length=200)
34
+ print("\nGenerated Report:")
35
+ print(report[0]['generated_text'])