Update app.py
Browse files
app.py
CHANGED
@@ -9,18 +9,10 @@ from duckduckgo_search import DDGS
|
|
9 |
|
10 |
# Environment variables and configurations
|
11 |
huggingface_token = os.environ.get("HUGGINGFACE_TOKEN")
|
12 |
-
llama_cloud_api_key = os.environ.get("LLAMA_CLOUD_API_KEY")
|
13 |
-
ACCOUNT_ID = os.environ.get("CLOUDFARE_ACCOUNT_ID")
|
14 |
-
API_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
|
15 |
-
API_BASE_URL = f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/"
|
16 |
-
|
17 |
-
print(f"ACCOUNT_ID: {ACCOUNT_ID}")
|
18 |
-
print(f"CLOUDFLARE_AUTH_TOKEN: {API_TOKEN[:5]}..." if API_TOKEN else "Not set")
|
19 |
|
20 |
MODELS = [
|
21 |
"mistralai/Mistral-7B-Instruct-v0.3",
|
22 |
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
23 |
-
"@cf/meta/llama-3.1-8b-instruct",
|
24 |
"mistralai/Mistral-Nemo-Instruct-2407"
|
25 |
]
|
26 |
|
@@ -56,25 +48,20 @@ def get_response_with_search(query, model, num_calls=3, temperature=0.2):
|
|
56 |
Write a detailed and complete research document that fulfills the following user request: '{query}'
|
57 |
After writing the document, please provide a list of sources used in your response."""
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
):
|
74 |
-
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
75 |
-
chunk = message.choices[0].delta.content
|
76 |
-
main_content += chunk
|
77 |
-
yield main_content, ""
|
78 |
|
79 |
def respond(message, history, model, temperature, num_calls):
|
80 |
logging.info(f"User Query: {message}")
|
@@ -101,6 +88,7 @@ css = """
|
|
101 |
width: 100%;
|
102 |
}
|
103 |
"""
|
|
|
104 |
# Gradio interface setup
|
105 |
def create_gradio_interface():
|
106 |
custom_placeholder = "Enter your question here for web search."
|
@@ -108,7 +96,7 @@ def create_gradio_interface():
|
|
108 |
demo = gr.ChatInterface(
|
109 |
respond,
|
110 |
additional_inputs=[
|
111 |
-
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[
|
112 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
|
113 |
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
|
114 |
],
|
|
|
9 |
|
10 |
# Environment variables and configurations
|
11 |
huggingface_token = os.environ.get("HUGGINGFACE_TOKEN")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
MODELS = [
|
14 |
"mistralai/Mistral-7B-Instruct-v0.3",
|
15 |
"mistralai/Mixtral-8x7B-Instruct-v0.1",
|
|
|
16 |
"mistralai/Mistral-Nemo-Instruct-2407"
|
17 |
]
|
18 |
|
|
|
48 |
Write a detailed and complete research document that fulfills the following user request: '{query}'
|
49 |
After writing the document, please provide a list of sources used in your response."""
|
50 |
|
51 |
+
# Use Hugging Face API
|
52 |
+
client = InferenceClient(model, token=huggingface_token)
|
53 |
+
main_content = ""
|
54 |
+
for i in range(num_calls):
|
55 |
+
for message in client.chat_completion(
|
56 |
+
messages=[{"role": "user", "content": prompt}],
|
57 |
+
max_tokens=10000,
|
58 |
+
temperature=temperature,
|
59 |
+
stream=True,
|
60 |
+
):
|
61 |
+
if message.choices and message.choices[0].delta and message.choices[0].delta.content:
|
62 |
+
chunk = message.choices[0].delta.content
|
63 |
+
main_content += chunk
|
64 |
+
yield main_content, ""
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
def respond(message, history, model, temperature, num_calls):
|
67 |
logging.info(f"User Query: {message}")
|
|
|
88 |
width: 100%;
|
89 |
}
|
90 |
"""
|
91 |
+
|
92 |
# Gradio interface setup
|
93 |
def create_gradio_interface():
|
94 |
custom_placeholder = "Enter your question here for web search."
|
|
|
96 |
demo = gr.ChatInterface(
|
97 |
respond,
|
98 |
additional_inputs=[
|
99 |
+
gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[2]),
|
100 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature"),
|
101 |
gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls"),
|
102 |
],
|