runaksh commited on
Commit
5731682
·
1 Parent(s): 1fc3bc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -50
app.py CHANGED
@@ -24,56 +24,32 @@ def predict_sentiment(text):
24
  return 'Positive'
25
 
26
  def predict(sample, validate=True):
27
- classifier = pipeline("text-classification", model=model_2, tokenizer=tokenizer_2)
28
  pred = classifier(sample)[0]['label']
29
  return pred
30
 
31
- # Input from user
32
- in_prompt_1 = gradio.components.Textbox(lines=10, placeholder=None, label='Enter review text')
33
-
34
- # Output response
35
- out_response_1 = gradio.components.Textbox(type="text", label='Sentiment')
36
-
37
- # Gradio interface to generate UI link
38
- title_1 = "Sentiment Classification"
39
- description_1 = "Analyse sentiment of the given review"
40
-
41
- iface_1 = gradio.Interface(fn = predict_sentiment,
42
- inputs = [in_prompt_1],
43
- outputs = [out_response_1],
44
- title = title_1,
45
- description = description_1)
46
-
47
- title_2 = "Symptoms and Disease"
48
- description_2 = "Enter the Symptoms to know the disease"
49
-
50
- # Input from user
51
- in_prompt_2 = gradio.components.Textbox(lines=2, label='Enter the Symptoms')
52
-
53
- # Output response
54
- out_response_2 = gradio.components.Textbox(label='Disease')
55
-
56
- # Gradio interface to generate UI link
57
- iface_2 = gradio.Interface(fn=predict,
58
- inputs = [in_prompt_2],
59
- outputs = [out_response_2],
60
- title=title_2,
61
- description=description_2
62
- )
63
-
64
- def combined_interface(input1, input2):
65
- # Call individual model interfaces and combine results
66
- model1_output = iface_1(input1)
67
- model2_output = iface_2(input2)
68
-
69
- combined_output = {
70
- "model1_output": model1_output,
71
- "model2_output": model2_output
72
- }
73
-
74
- return combined_output
75
-
76
- parent_interface = gradio.Interface(fn=combined_interface, inputs=["text","text"], outputs=["model1_output", "model2_output"])
77
-
78
- parent_interface.launch(debug = True)
79
- #iface.launch(debug = True)#, server_name = "0.0.0.0", server_port = 8001) # Ref. for parameters: https://www.gradio.app/docs/interface
 
24
  return 'Positive'
25
 
26
  def predict(sample, validate=True):
 
27
  pred = classifier(sample)[0]['label']
28
  return pred
29
 
30
+ def make_block(dem):
31
+ with dem:
32
+ gr.Markdown("""
33
+ # Ejemplo de `space` multiclassifier: Curso Platzi""")
34
+ with gr.Tabs():
35
+ with gr.TabItem("Transcribe audio en español"):
36
+ with gr.Row():
37
+ in_prompt_1 = gradio.components.Textbox(lines=10, placeholder=None, label='Enter review text')
38
+ out_response_1 = gradio.components.Textbox(type="text", label='Sentiment')
39
+ b1 = gr.Button("Voz a Texto")
40
+
41
+ with gr.TabItem("Análisis de sentimiento en español"):
42
+ with gr.Row():
43
+ in_prompt_2 = gradio.components.Textbox(lines=2, label='Enter the Symptoms')
44
+ out_response_2 = gradio.components.Textbox(label='Disease')
45
+ b2 = gr.Button("Texto a Sentimiento")
46
+ b1.click(predict_sentiment, inputs=in_prompt_1, outputs=out_response_1)
47
+ b2.click(predict, inputs=in_prompt_2, outputs=out_response_2)
48
+
49
+ if __name__ == '__main__':
50
+ model_1 = pipeline(model= repo_path)
51
+ classifier = pipeline("text-classification", model=model_2, tokenizer=tokenizer_2)
52
+
53
+ demo = gr.Blocks()
54
+ make_block(demo)
55
+ demo.launch()