RamezCh commited on
Commit
cb57e70
·
verified ·
1 Parent(s): 098be50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -2
app.py CHANGED
@@ -22,8 +22,37 @@ def sentiment_analysis(text: str) -> dict:
22
  }
23
 
24
 
25
- # Create the Gradio interface
26
- demo = gr.Interface(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  fn=sentiment_analysis,
28
  inputs=gr.Textbox(placeholder="Enter text to analyze..."),
29
  outputs=gr.JSON(),
@@ -31,6 +60,20 @@ demo = gr.Interface(
31
  description="Analyze the sentiment of text using TextBlob"
32
  )
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # Launch the interface and MCP server
35
  if __name__ == "__main__":
36
  demo.launch(mcp_server=True)
 
22
  }
23
 
24
 
25
+ def prime_factorization(n: int) -> dict:
26
+ """
27
+ Compute the prime factorization of a number.
28
+
29
+ Args:
30
+ n (int): Positive integer
31
+
32
+ Returns:
33
+ dict: Prime factors and their exponents (with string keys for JSON compatibility)
34
+ """
35
+ if n <= 0:
36
+ return {"error": "Please enter a positive integer."}
37
+
38
+ i = 2
39
+ factors = {}
40
+ while i * i <= n:
41
+ while n % i == 0:
42
+ factors[i] = factors.get(i, 0) + 1
43
+ n //= i
44
+ i += 1
45
+ if n > 1:
46
+ factors[n] = 1
47
+
48
+ # Convert integer keys to strings
49
+ str_factors = {str(k): v for k, v in factors.items()}
50
+
51
+ return {"factors": str_factors}
52
+
53
+
54
+ # Define Gradio interfaces for each function
55
+ sentiment_interface = gr.Interface(
56
  fn=sentiment_analysis,
57
  inputs=gr.Textbox(placeholder="Enter text to analyze..."),
58
  outputs=gr.JSON(),
 
60
  description="Analyze the sentiment of text using TextBlob"
61
  )
62
 
63
+ factorization_interface = gr.Interface(
64
+ fn=prime_factorization,
65
+ inputs=gr.Number(value=1, label="Number", precision=0),
66
+ outputs=gr.JSON(),
67
+ title="Prime Factorization",
68
+ description="Compute the prime factorization of a number"
69
+ )
70
+
71
+ # Combine into a tabbed interface
72
+ demo = gr.TabbedInterface(
73
+ interface_list=[sentiment_interface, factorization_interface],
74
+ tab_names=["Sentiment Analysis", "Prime Factorization"]
75
+ )
76
+
77
  # Launch the interface and MCP server
78
  if __name__ == "__main__":
79
  demo.launch(mcp_server=True)