Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,25 @@
|
|
1 |
-
from fastapi import FastAPI
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
-
|
5 |
-
import requests
|
6 |
-
|
7 |
-
url = "https://seoroast.co/api/generate-youtube-titles"
|
8 |
-
|
9 |
-
h = {"Content-Type": "application/json",
|
10 |
-
"origin": "https://seoroast.co",
|
11 |
-
"accept": "*/*"}
|
12 |
-
|
13 |
-
payload = {"content":"A Car Experiment","model":"google/gemini-flash-1.5","tone":"auto"}
|
14 |
-
|
15 |
-
r = requests.post(url, headers=h, json=payload)
|
16 |
-
|
17 |
-
print(r.json()["result"])
|
18 |
@app.get("/")
|
19 |
def greet_json():
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
import requests
|
3 |
|
4 |
app = FastAPI()
|
5 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
@app.get("/")
|
7 |
def greet_json():
|
8 |
+
url = "https://seoroast.co/api/generate-youtube-titles"
|
9 |
+
headers = {
|
10 |
+
"Content-Type": "application/json",
|
11 |
+
"origin": "https://seoroast.co",
|
12 |
+
"accept": "*/*"
|
13 |
+
}
|
14 |
+
payload = {
|
15 |
+
"content": "A Car Experiment",
|
16 |
+
"model": "google/gemini-flash-1.5",
|
17 |
+
"tone": "auto"
|
18 |
+
}
|
19 |
+
|
20 |
+
try:
|
21 |
+
response = requests.post(url, headers=headers, json=payload)
|
22 |
+
response.raise_for_status() # Raise an error for bad responses
|
23 |
+
return response.json() # Return the entire JSON response
|
24 |
+
except requests.exceptions.RequestException as e:
|
25 |
+
raise HTTPException(status_code=500, detail=str(e))
|