RCaz commited on
Commit
76a8957
·
verified ·
1 Parent(s): 96daeea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -50
app.py CHANGED
@@ -1,54 +1,34 @@
1
- import asyncio
2
- import sys
3
- import argparse
4
- from gradio_interface import create_gradio_interface
5
- from mcp_server import main as run_mcp_server
6
 
7
- def main():
8
- parser = argparse.ArgumentParser(description="Knowledge Graph Navigator")
9
- parser.add_argument(
10
- "--mode",
11
- choices=["gradio", "mcp", "both"],
12
- default="gradio",
13
- help="Run mode: gradio (web interface), mcp (server only), or both"
14
- )
15
- parser.add_argument(
16
- "--port",
17
- type=int,
18
- default=7860,
19
- help="Port for Gradio interface (default: 7860)"
20
- )
21
- parser.add_argument(
22
- "--share",
23
- action="store_true",
24
- help="Create public Gradio link"
25
- )
26
-
27
- args = parser.parse_args()
28
-
29
- if args.mode == "gradio":
30
- print("🚀 Launching Gradio interface...")
31
- interface = create_gradio_interface()
32
- interface.launch(
33
- server_port=args.port,
34
- share=args.share,
35
- debug=True
36
- )
37
-
38
- elif args.mode == "mcp":
39
- print("🔧 Starting MCP server...")
40
- asyncio.run(run_mcp_server())
41
 
42
- elif args.mode == "both":
43
- print("🚀 Starting both Gradio and MCP server...")
44
- # In production, you'd want to run these in separate processes
45
- # For now, just run Gradio (MCP would run in background)
46
- interface = create_gradio_interface()
47
- interface.launch(
48
- server_port=args.port,
49
- share=args.share,
50
- debug=True
51
- )
 
 
 
 
52
 
 
53
  if __name__ == "__main__":
54
- main()
 
1
+ import gradio as gr
2
+ from textblob import TextBlob
 
 
 
3
 
4
+ def sentiment_analysis(text: str) -> dict:
5
+ """
6
+ Analyze the sentiment of the given text.
7
+
8
+ Args:
9
+ text (str): The text to analyze
10
+
11
+ Returns:
12
+ dict: A dictionary containing polarity, subjectivity, and assessment
13
+ """
14
+ blob = TextBlob(text)
15
+ sentiment = blob.sentiment
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ return {
18
+ "polarity": round(sentiment.polarity, 2), # -1 (negative) to 1 (positive)
19
+ "subjectivity": round(sentiment.subjectivity, 2), # 0 (objective) to 1 (subjective)
20
+ "assessment": "positive" if sentiment.polarity > 0 else "negative" if sentiment.polarity < 0 else "neutral"
21
+ }
22
+
23
+ # Create the Gradio interface
24
+ demo = gr.Interface(
25
+ fn=sentiment_analysis,
26
+ inputs=gr.Textbox(placeholder="Enter text to analyze..."),
27
+ outputs=gr.JSON(),
28
+ title="Text Sentiment Analysis",
29
+ description="Analyze the sentiment of text using TextBlob"
30
+ )
31
 
32
+ # Launch the interface and MCP server
33
  if __name__ == "__main__":
34
+ demo.launch(mcp_server=True)