Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import requests
|
| 4 |
-
from transformers import AutoTokenizer
|
| 5 |
|
| 6 |
# Define Hugging Face API details
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/Huzaifa367/chat-summarizer"
|
|
@@ -10,8 +9,12 @@ HEADERS = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
| 10 |
|
| 11 |
# Define function to query Hugging Face API for summarization
|
| 12 |
def query_huggingface(payload):
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Define response function for Gradio chat interface
|
| 17 |
def respond(
|
|
@@ -42,14 +45,16 @@ def respond(
|
|
| 42 |
return summary_text
|
| 43 |
|
| 44 |
# Define Gradio chat interface
|
| 45 |
-
demo = gr.
|
| 46 |
-
respond,
|
| 47 |
-
|
| 48 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 49 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 50 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 51 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
| 52 |
],
|
|
|
|
|
|
|
| 53 |
)
|
| 54 |
|
| 55 |
# Launch the Gradio chat interface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import requests
|
|
|
|
| 4 |
|
| 5 |
# Define Hugging Face API details
|
| 6 |
API_URL = "https://api-inference.huggingface.co/models/Huzaifa367/chat-summarizer"
|
|
|
|
| 9 |
|
| 10 |
# Define function to query Hugging Face API for summarization
|
| 11 |
def query_huggingface(payload):
|
| 12 |
+
try:
|
| 13 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 14 |
+
response.raise_for_status() # Raise exception for non-2xx status codes
|
| 15 |
+
return response.json()["summary"]
|
| 16 |
+
except requests.exceptions.RequestException as e:
|
| 17 |
+
return f"Error: {e}"
|
| 18 |
|
| 19 |
# Define response function for Gradio chat interface
|
| 20 |
def respond(
|
|
|
|
| 45 |
return summary_text
|
| 46 |
|
| 47 |
# Define Gradio chat interface
|
| 48 |
+
demo = gr.Interface(
|
| 49 |
+
fn=respond,
|
| 50 |
+
inputs=[
|
| 51 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 52 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 53 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 54 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
| 55 |
],
|
| 56 |
+
outputs=gr.Textbox(label="Summary"),
|
| 57 |
+
title="Chat Summarizer",
|
| 58 |
)
|
| 59 |
|
| 60 |
# Launch the Gradio chat interface
|