Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -10,6 +10,8 @@ from fastapi import Query
|
|
| 10 |
from pydantic import BaseModel
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
from helper_functions_api import md_to_html
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Retrieve environment variables
|
| 15 |
TOGETHER_API_KEY = os.getenv("TOGETHER_API_KEY")
|
|
@@ -66,7 +68,12 @@ def generate_report(topic, description):
|
|
| 66 |
md_report = together_response(prompt, model = "meta-llama/Llama-3-70b-chat-hf", SysPrompt = SysPromptMdOffline)
|
| 67 |
return md_to_html(md_report)
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
# Define the app
|
| 71 |
app = FastAPI()
|
| 72 |
|
|
@@ -101,4 +108,8 @@ async def create_topics(input: TopicInput):
|
|
| 101 |
async def create_report(input: ReportInput):
|
| 102 |
report = generate_report(input.topic, input.description) # You'll need to implement this function
|
| 103 |
return {"report": report}
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
from pydantic import BaseModel
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
from helper_functions_api import md_to_html
|
| 13 |
+
from duckduckgo_search import DDGS
|
| 14 |
+
import time
|
| 15 |
|
| 16 |
# Retrieve environment variables
|
| 17 |
TOGETHER_API_KEY = os.getenv("TOGETHER_API_KEY")
|
|
|
|
| 68 |
md_report = together_response(prompt, model = "meta-llama/Llama-3-70b-chat-hf", SysPrompt = SysPromptMdOffline)
|
| 69 |
return md_to_html(md_report)
|
| 70 |
|
| 71 |
+
def get_images(query, num_results):
|
| 72 |
+
time.sleep(0.5)
|
| 73 |
+
ddgs = DDGS()
|
| 74 |
+
imgs = ddgs.images(keywords=query, safesearch="on", max_results=num_results)
|
| 75 |
+
return imgs
|
| 76 |
+
|
| 77 |
# Define the app
|
| 78 |
app = FastAPI()
|
| 79 |
|
|
|
|
| 108 |
async def create_report(input: ReportInput):
|
| 109 |
report = generate_report(input.topic, input.description) # You'll need to implement this function
|
| 110 |
return {"report": report}
|
| 111 |
+
|
| 112 |
+
@app.post("/get_images")
|
| 113 |
+
async def get_images(input: ReportInput):
|
| 114 |
+
images = get_images(input.user_input, input.num_topics)
|
| 115 |
+
return {"images": images}
|