Homeskills commited on
Commit
6fa7231
1 Parent(s): 5f732b0

update app.py and add requirements.txt

Browse files
Files changed (2) hide show
  1. app.py +49 -4
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,7 +1,52 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from utils import T5Generator
3
 
 
 
4
 
5
+ # Preprocessing function that modifies the user input.
6
+ def preprocess_input(user_input):
7
+ bos_instruction_id = """Definition: The output will be the aspects (both implicit and explicit) and the aspect's sentiment polarity. In cases where there are no aspects the output should be noaspectterm:none.
8
+ Positive example 1-
9
+ input: With the great variety on the menu , I eat here often and never get bored.
10
+ output: menu:positive
11
+ Positive example 2-
12
+ input: Great food, good size menu, great service and an unpretentious setting.
13
+ output: food:positive, menu:positive, service:positive, setting:positive
14
+ Negative example 1-
15
+ input: They did not have mayonnaise, forgot our toast, left out ingredients (ie cheese in an omelet), below hot temperatures and the bacon was so over cooked it crumbled on the plate when you touched it.
16
+ output: toast:negative, mayonnaise:negative, bacon:negative, ingredients:negative, plate:negative
17
+ Negative example 2-
18
+ input: The seats are uncomfortable if you are sitting against the wall on wooden benches.
19
+ output: seats:negative
20
+ Neutral example 1-
21
+ input: I asked for seltzer with lime, no ice.
22
+ output: seltzer with lime:neutral
23
+ Neutral example 2-
24
+ input: They wouldn't even let me finish my glass of wine before offering another.
25
+ output: glass of wine:neutral
26
+ Now complete the following example-
27
+ input: """
28
+ eos_instruction = ' \noutput:'
29
+ # Append and prepend the text to the user's input.
30
+ modified_input = bos_instruction_id + user_input + eos_instruction
31
+ return modified_input
32
+
33
+
34
+ # Assuming you have a function `model_predict` that takes the processed text and returns a prediction.
35
+ def model_predict(processed_text):
36
+ # Here you would include the logic to make a prediction based on the processed_text.
37
+ # This example simply returns the processed text.
38
+ # tokenize input
39
+ input_ids = t5_exp.tokenizer(processed_text, return_tensors="pt").input_ids
40
+ # generate output
41
+ outputs = t5_exp.model.generate(input_ids, max_length=128)
42
+ return t5_exp.tokenizer.decode(outputs[0], skip_special_tokens=True)
43
+
44
+
45
+ # Create T5 model object along with instructions
46
+ model_checkpoint = "Homeskills/mt_instruct_absa"
47
+ t5_exp = T5Generator(model_checkpoint)
48
+
49
+ iface = gr.Interface(fn=lambda x: model_predict(preprocess_input(x)),
50
+ inputs=[gr.Textbox(label="Input review text here")],
51
+ outputs=gr.Textbox(label="Extracted aspects & sentiment"))
52
+ iface.launch()
requirements.txt CHANGED
@@ -3,4 +3,5 @@ transformers
3
  datasets
4
  evaluate
5
  sentencepiece
6
- gradio
 
 
3
  datasets
4
  evaluate
5
  sentencepiece
6
+ gradio
7
+ scikit-learn