fahmiaziz98 commited on
Commit
4ca551f
·
1 Parent(s): b08d3ea

frist commit

Browse files
Files changed (1) hide show
  1. app.py +63 -11
app.py CHANGED
@@ -1,20 +1,15 @@
1
  from typing import Union
2
 
3
  from fastapi import FastAPI
4
- from pydantic import BaseModel
5
 
6
  app = FastAPI()
7
 
8
 
9
- class Item(BaseModel):
10
- name: str
11
- price: float
12
- is_offer: Union[bool, None] = None
13
-
14
-
15
  @app.get("/")
16
  def read_root():
17
- return {"Status": "Running"}
 
18
 
19
 
20
  @app.get("/items/{item_id}")
@@ -22,6 +17,63 @@ def read_item(item_id: int, q: Union[str, None] = None):
22
  return {"item_id": item_id, "q": q}
23
 
24
 
25
- @app.put("/items/{item_id}")
26
- def update_item(item_id: int, item: Item):
27
- return {"item_name": item.name, "item_id": item_id}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from typing import Union
2
 
3
  from fastapi import FastAPI
4
+ from fastapi import Request
5
 
6
  app = FastAPI()
7
 
8
 
 
 
 
 
 
 
9
  @app.get("/")
10
  def read_root():
11
+ return {"Hello": "World!!!"}
12
+ # return "This is string"
13
 
14
 
15
  @app.get("/items/{item_id}")
 
17
  return {"item_id": item_id, "q": q}
18
 
19
 
20
+ @app.get("/get_sentiment/{text}")
21
+ def get_sentiment(text: str, user_id: Union[str, None] = None):
22
+ return {"text": text,
23
+ "sentiment": "positive",
24
+ "user_id": user_id}
25
+
26
+ @app.get("/get_sentiment_v2/{text}/{ip}")
27
+ def get_sentiment_v2(text: str, ip: str, user_id: Union[str, None] = None):
28
+ return {"ip": ip,
29
+ "text": text,
30
+ "sentiment": "positive",
31
+ "user_id": user_id}
32
+
33
+
34
+ @app.post("/get_twitter_sentiment")
35
+ def get_twitter_sentiment(text: str, ip: str, user_id: Union[str, None] = None):
36
+ """
37
+ Analyze the sentiment of a given text from Twitter.
38
+
39
+ Parameters:
40
+ - text (str): The text to analyze.
41
+ - ip (str): The IP address of the user.
42
+ - user_id (Union[str, None]): Optional user ID for tracking.
43
+
44
+ Returns:
45
+ - A JSON object containing the IP, text, sentiment analysis result, and user ID.
46
+ """
47
+ return {
48
+ "ip": ip,
49
+ "text": text,
50
+ "sentiment": "normal", # Placeholder for sentiment analysis
51
+ "user_id": user_id
52
+ }
53
+
54
+ @app.post("/get_twitter_sentiment_v2")
55
+ async def get_twitter_sentiment_v2(request: Request):
56
+ """
57
+ Analyze the sentiment of a given text from Twitter asynchronously.
58
+
59
+ This endpoint accepts a JSON body with the following fields:
60
+ - text (str): The text to analyze.
61
+ - ip (str): The IP address of the user.
62
+ - user_id (Union[str, None]): Optional user ID for tracking.
63
+
64
+ Returns:
65
+ - A JSON object containing the IP, text, sentiment analysis result, and user ID.
66
+ """
67
+ data = await request.json()
68
+
69
+ text: str = data.get('text')
70
+ ip = data.get('ip')
71
+ user_id = data.get('user_id')
72
+
73
+ return {
74
+ "ip": ip,
75
+ "text": text,
76
+ "sentiment": "normal", # Placeholder for sentiment analysis
77
+ "user_id": user_id
78
+ }
79
+