Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
-
from
|
4 |
|
5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
|
|
|
6 |
duckduckgo_search = DuckDuckGoSearchRun()
|
7 |
|
8 |
def format_prompt(message, history):
|
@@ -29,22 +31,24 @@ def generate(prompt, history, system_prompt, temperature=0.9, max_new_tokens=256
|
|
29 |
)
|
30 |
|
31 |
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
|
|
|
|
32 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
|
|
33 |
|
34 |
for response in stream:
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
yield generated_response
|
46 |
|
47 |
-
additional_inputs=[
|
48 |
gr.Textbox(
|
49 |
label="System Prompt",
|
50 |
max_lines=1,
|
@@ -88,15 +92,15 @@ additional_inputs=[
|
|
88 |
)
|
89 |
]
|
90 |
|
91 |
-
examples=[
|
92 |
-
["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None
|
93 |
-
["What are some best tourist places to visit in Lajpat nagar, Delhi?", None, None, None, None, None
|
94 |
-
["Ronaldo or Messi?", None, None, None, None, None
|
95 |
-
["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None
|
96 |
]
|
97 |
|
98 |
gr.ChatInterface(
|
99 |
-
fn=
|
100 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
101 |
additional_inputs=additional_inputs,
|
102 |
title="🤗 friday2.0 🤗 WELCOME TO OPEN-SOURCE FREEDOM",
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
+
from langchain.tools import DuckDuckGoSearchRun
|
4 |
|
5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
6 |
+
|
7 |
+
# Initialize DuckDuckGo search tool
|
8 |
duckduckgo_search = DuckDuckGoSearchRun()
|
9 |
|
10 |
def format_prompt(message, history):
|
|
|
31 |
)
|
32 |
|
33 |
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
34 |
+
|
35 |
+
# Generate response using model
|
36 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
37 |
+
output = ""
|
38 |
|
39 |
for response in stream:
|
40 |
+
output += response.token.text
|
41 |
+
# Yield model's response first
|
42 |
+
yield output
|
43 |
+
|
44 |
+
# Now, perform DuckDuckGo search and yield results
|
45 |
+
search_result = duckduckgo_search.run(prompt)
|
46 |
+
if search_result:
|
47 |
+
yield search_result
|
48 |
+
else:
|
49 |
+
yield "Sorry, I couldn't find any relevant information."
|
|
|
50 |
|
51 |
+
additional_inputs = [
|
52 |
gr.Textbox(
|
53 |
label="System Prompt",
|
54 |
max_lines=1,
|
|
|
92 |
)
|
93 |
]
|
94 |
|
95 |
+
examples = [
|
96 |
+
["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None],
|
97 |
+
["What are some best tourist places to visit in Lajpat nagar, Delhi?", None, None, None, None, None],
|
98 |
+
["Ronaldo or Messi?", None, None, None, None, None],
|
99 |
+
["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None],
|
100 |
]
|
101 |
|
102 |
gr.ChatInterface(
|
103 |
+
fn=generate,
|
104 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
105 |
additional_inputs=additional_inputs,
|
106 |
title="🤗 friday2.0 🤗 WELCOME TO OPEN-SOURCE FREEDOM",
|