Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,7 +46,9 @@ Always respond with the chord name and a short explanation of the intervals.
|
|
| 46 |
|
| 47 |
# Read token from Secrets (set in Space -> Settings -> Repository secrets)
|
| 48 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
|
| 51 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 52 |
if HF_TOKEN is None:
|
|
@@ -57,19 +59,17 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 57 |
prompt = f"{system_message}\nUser: {message}\nAnswer:"
|
| 58 |
response = ""
|
| 59 |
|
| 60 |
-
for chunk in client.
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
},
|
| 68 |
-
"stream": True,
|
| 69 |
-
}
|
| 70 |
):
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 73 |
response += token
|
| 74 |
yield response.strip()
|
| 75 |
|
|
@@ -81,7 +81,6 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 81 |
yield f"⚠️ Error: {str(e)}\n\nTraceback:\n{tb}"
|
| 82 |
|
| 83 |
|
| 84 |
-
|
| 85 |
chatbot = gr.ChatInterface(
|
| 86 |
fn=respond,
|
| 87 |
additional_inputs=[
|
|
|
|
| 46 |
|
| 47 |
# Read token from Secrets (set in Space -> Settings -> Repository secrets)
|
| 48 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 49 |
+
|
| 50 |
+
# Create inference client
|
| 51 |
+
client = InferenceClient(token=HF_TOKEN)
|
| 52 |
|
| 53 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 54 |
if HF_TOKEN is None:
|
|
|
|
| 59 |
prompt = f"{system_message}\nUser: {message}\nAnswer:"
|
| 60 |
response = ""
|
| 61 |
|
| 62 |
+
for chunk in client.text_generation(
|
| 63 |
+
prompt,
|
| 64 |
+
model="google/flan-t5-small", # ✅ ensure correct model is used
|
| 65 |
+
max_new_tokens=max_tokens,
|
| 66 |
+
temperature=temperature,
|
| 67 |
+
top_p=top_p,
|
| 68 |
+
stream=True,
|
|
|
|
|
|
|
|
|
|
| 69 |
):
|
| 70 |
+
# chunks are StreamingResponse objects
|
| 71 |
+
if hasattr(chunk, "token") and chunk.token and chunk.token.text:
|
| 72 |
+
token = chunk.token.text
|
| 73 |
response += token
|
| 74 |
yield response.strip()
|
| 75 |
|
|
|
|
| 81 |
yield f"⚠️ Error: {str(e)}\n\nTraceback:\n{tb}"
|
| 82 |
|
| 83 |
|
|
|
|
| 84 |
chatbot = gr.ChatInterface(
|
| 85 |
fn=respond,
|
| 86 |
additional_inputs=[
|