Barandnmz21 commited on
Commit
7355b67
·
verified ·
1 Parent(s): 8bb5e78

Upload 3 files

Browse files
Files changed (3) hide show
  1. __init__.py +1 -0
  2. main.py +11 -0
  3. services.py +33 -0
__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+
main.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+
3
+ app = FastAPI()
4
+
5
+ @app.get("/")
6
+ def read_root():
7
+ return {"message": "AI Social Media Bot is running!"}
8
+
9
+ @app.get("/fetch-trends")
10
+ def fetch_trends():
11
+ return {"trends": ["Data Science", "Python", "Cybersecurity"]}
services.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+ from typing import List
4
+
5
+ OPENROUTER_KEY = os.getenv("OPENROUTER_API_KEY", "")
6
+
7
+
8
+ def get_trends() -> List[str]:
9
+ return ["Data Science", "Python", "Cybersecurity"]
10
+
11
+
12
+ def analyze_trends(trends: List[str]) -> str:
13
+ text = ", ".join(trends)
14
+ summary = f"Summary: trending topics are {text}. These show strong interest in AI and data."
15
+
16
+ if OPENROUTER_KEY:
17
+ try:
18
+ url = "https://openrouter.ai/v1/chat/completions"
19
+ headers = {"Authorization": f"Bearer {OPENROUTER_KEY}"}
20
+ prompt = f"Analyze these trending topics and return a short summary: {text}"
21
+ body = {
22
+ "model": "meta-llama/Llama-2-13b-chat",
23
+ "messages": [{"role": "user", "content": prompt}],
24
+ "max_tokens": 200,
25
+ }
26
+ r = requests.post(url, json=body, headers=headers, timeout=20)
27
+ r.raise_for_status()
28
+ data = r.json()
29
+
30
+ return data["choices"][0]["message"]["content"]
31
+ except Exception:
32
+ return summary
33
+ return summary