thuyentruong commited on
Commit
1c012dd
·
verified ·
1 Parent(s): 1b3b89f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -5
app.py CHANGED
@@ -1,10 +1,42 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
- pipe = pipeline(task="image-classification",
5
- model="thuyentruong/food_classification_model")
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  gr.Interface.from_pipeline(pipe,
7
- title="Food Image Classification",
8
- description="Image classification",
9
- examples = ['beignets.jpeg','spagetti.jpeg'],
10
  ).launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ Examples_to_teach_model=f"""
4
+ Text: I hate apples
5
+ Sentiment analysis:
6
+ Sentiments: Negative
7
+ PPrint Key words: hate, aples
8
+ Text: I enjoy watching movies
9
+ Sentiment analysis:
10
+ Sentiments: Positive
11
+ PPrint Key words: enjoy, movies
12
+ Text: I'm tired of this long process
13
+ Sentiment analysis:
14
+ Sentiments: Negative
15
+ PPrint Key words: tired, long process
16
+ """
17
+ question="""
18
+ Text: I love chips.
19
+ Sentiment analysis:
20
+ """
21
+ def make_prompt(sentence):
22
+ prompt = Examples_to_teach_model+ "Text: " + sentence + "Sentiment analysis:"
23
 
24
+ return prompt
25
+
26
+ def get_sentiment_from_llm(sentence):
27
+ input = make_prompt(sentence)
28
+ inputs = tokenizer(input, return_tensors='pt')
29
+ output = tokenizer.decode(
30
+ model.generate(
31
+ inputs["input_ids"],
32
+ max_new_tokens=100,
33
+ )[0],
34
+ skip_special_tokens=True)
35
+ return "\n".join(output.split('PPrint '))
36
+
37
+ get_rules_from_llm(question)
38
+
39
  gr.Interface.from_pipeline(pipe,
40
+ title="Sentiment Analysis",
41
+ description="Sentiment analysis and keywords extraction.",
 
42
  ).launch()