Muhammad Anas Akhtar commited on
Commit
b89e85f
1 Parent(s): b3a2aa9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ # Initialize the sentiment-analysis pipeline
6
+ semantic_analysis = pipeline("sentiment-analysis", model="BAAI/bge-reranker-v2-m3")
7
+
8
+ # Define a function to analyze text semantics
9
+ def analyze_semantics(input_text):
10
+ # Get the result from the pipeline
11
+ result = semantic_analysis(input_text)
12
+ # Extract label (e.g., Positive/Negative) and confidence score
13
+ label = result[0]['label']
14
+ confidence = round(result[0]['score'] * 100, 2)
15
+ return f"Sentiment: {label} (Confidence: {confidence}%)"
16
+
17
+ # Set up the Gradio interface
18
+ gr.close_all()
19
+
20
+ Demo = gr.Interface(
21
+ fn=analyze_semantics,
22
+ inputs=[gr.Textbox(label="Enter Text for Semantic Analysis", lines=5)],
23
+ outputs=[gr.Textbox(label="Semantic Analysis Result", lines=2)],
24
+ title="Semantic Analysis App",
25
+ description="This application performs semantic analysis to determine the sentiment of the given text."
26
+ )
27
+
28
+ # Launch the app with a public link
29
+ Demo.launch(share=True)