Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,9 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
def query(payload):
|
| 9 |
response = requests.post(API_URL, headers={"Authorization": f"Bearer {API_KEY}"}, json=payload)
|
|
@@ -11,7 +12,11 @@ def query(payload):
|
|
| 11 |
|
| 12 |
def chatbot(input_text):
|
| 13 |
response = query({"inputs": input_text})
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
demo = gr.Interface(fn=chatbot, inputs="text", outputs="text")
|
| 17 |
demo.launch()
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Замените URL модели на подходящий URL модели Gemini
|
| 6 |
+
API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-neo-2.7B"
|
| 7 |
+
API_KEY = os.getenv('Sec1') # Используем переменную окружения
|
| 8 |
|
| 9 |
def query(payload):
|
| 10 |
response = requests.post(API_URL, headers={"Authorization": f"Bearer {API_KEY}"}, json=payload)
|
|
|
|
| 12 |
|
| 13 |
def chatbot(input_text):
|
| 14 |
response = query({"inputs": input_text})
|
| 15 |
+
print(response) # Выводим ответ от API в консоль для отладки
|
| 16 |
+
try:
|
| 17 |
+
return response[0]['generated_text']
|
| 18 |
+
except (KeyError, IndexError):
|
| 19 |
+
return "Error: Unable to generate text. Please try again."
|
| 20 |
|
| 21 |
demo = gr.Interface(fn=chatbot, inputs="text", outputs="text")
|
| 22 |
demo.launch()
|