Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from duckduckgo_search import DDGS
|
| 3 |
-
from typing import List, Dict
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
import os
|
| 6 |
|
|
@@ -51,7 +51,7 @@ def rephrase_query(previous_response: str, new_query: str) -> str:
|
|
| 51 |
response = client.text_generation(prompt, max_new_tokens=100, temperature=0.7)
|
| 52 |
return response
|
| 53 |
|
| 54 |
-
def web_search_and_summarize(input_text: str, chat_history: List[str]) -> str:
|
| 55 |
if chat_history:
|
| 56 |
previous_response = chat_history[-1][1]
|
| 57 |
rephrased_query = rephrase_query(previous_response, input_text)
|
|
@@ -60,20 +60,22 @@ def web_search_and_summarize(input_text: str, chat_history: List[str]) -> str:
|
|
| 60 |
|
| 61 |
search_results = get_web_search_results(rephrased_query)
|
| 62 |
if "error" in search_results[0]:
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
return summary
|
| 67 |
|
| 68 |
iface = gr.Interface(
|
| 69 |
fn=web_search_and_summarize,
|
| 70 |
inputs=[
|
| 71 |
gr.Textbox(lines=2, placeholder="Enter your query here..."),
|
| 72 |
-
|
| 73 |
],
|
| 74 |
outputs=[
|
| 75 |
gr.Textbox(label="Response"),
|
| 76 |
-
|
| 77 |
],
|
| 78 |
title="DuckDuckGo Web Search and Summary",
|
| 79 |
description="Enter a query to get a summary based on web search results using DuckDuckGo.",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from duckduckgo_search import DDGS
|
| 3 |
+
from typing import List, Dict, Tuple
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
import os
|
| 6 |
|
|
|
|
| 51 |
response = client.text_generation(prompt, max_new_tokens=100, temperature=0.7)
|
| 52 |
return response
|
| 53 |
|
| 54 |
+
def web_search_and_summarize(input_text: str, chat_history: List[Tuple[str, str]]) -> Tuple[str, List[Tuple[str, str]]]:
|
| 55 |
if chat_history:
|
| 56 |
previous_response = chat_history[-1][1]
|
| 57 |
rephrased_query = rephrase_query(previous_response, input_text)
|
|
|
|
| 60 |
|
| 61 |
search_results = get_web_search_results(rephrased_query)
|
| 62 |
if "error" in search_results[0]:
|
| 63 |
+
summary = search_results[0]["error"]
|
| 64 |
+
else:
|
| 65 |
+
summary = summarize_results(rephrased_query, search_results)
|
| 66 |
|
| 67 |
+
chat_history.append((input_text, summary))
|
| 68 |
+
return summary, chat_history
|
| 69 |
|
| 70 |
iface = gr.Interface(
|
| 71 |
fn=web_search_and_summarize,
|
| 72 |
inputs=[
|
| 73 |
gr.Textbox(lines=2, placeholder="Enter your query here..."),
|
| 74 |
+
gr.State([])
|
| 75 |
],
|
| 76 |
outputs=[
|
| 77 |
gr.Textbox(label="Response"),
|
| 78 |
+
gr.State()
|
| 79 |
],
|
| 80 |
title="DuckDuckGo Web Search and Summary",
|
| 81 |
description="Enter a query to get a summary based on web search results using DuckDuckGo.",
|