Rizonando commited on
Commit
e5804f1
路
verified 路
1 Parent(s): 304c2e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,28 +1,30 @@
1
- # SMART - Interfaz tipo ChatGPT usando Gradio
2
 
3
  import gradio as gr
4
  import requests
5
 
6
- API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
7
- HEADERS = {"Authorization": f"Bearer TU_TOKEN_AQUI"} # <- Pega tu token aqu铆
 
8
 
9
  # Funci贸n para enviar mensaje a la API de Hugging Face
10
  def chat_with_smart(message, history):
11
  history = history or []
12
- full_prompt = "\n".join([f"Usuario: {msg}\nAsistente: {resp}" for msg, resp in history])
13
- full_prompt += f"\nUsuario: {message}\nAsistente:"
14
 
15
  try:
16
- response = requests.post(API_URL, headers=HEADERS, json={"inputs": full_prompt})
17
  response.raise_for_status()
18
  output = response.json()
19
 
20
  if isinstance(output, dict) and "error" in output:
21
  return history, f"[ERROR]: {output['error']}"
22
 
23
- generated = output[0]["generated_text"][len(full_prompt):].strip()
24
- history.append((message, generated))
25
- return history, generated
 
26
 
27
  except Exception as e:
28
  return history, f"[ERROR de conexi贸n]: {str(e)}"
@@ -44,7 +46,7 @@ def build_interface():
44
  msg = gr.Textbox(placeholder="Escribe un mensaje...", label="Mensaje")
45
  send = gr.Button("Enviar")
46
 
47
- state = gr.State([]) # historial
48
 
49
  send.click(fn=chat_with_smart, inputs=[msg, state], outputs=[state, chatbot])
50
  new_chat_btn.click(lambda: ([], None), outputs=[state, chatbot])
 
1
+ # SMART - Interfaz tipo ChatGPT usando Gradio y modelo p煤blico estable
2
 
3
  import gradio as gr
4
  import requests
5
 
6
+ # Usaremos un modelo p煤blico accesible sin restricciones complejas
7
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1"
8
+ HEADERS = {"Authorization": "Bearer hf_tu_token_aqui"} # <-- Reemplaza con tu token real
9
 
10
  # Funci贸n para enviar mensaje a la API de Hugging Face
11
  def chat_with_smart(message, history):
12
  history = history or []
13
+ prompt = "".join([f"Usuario: {msg}\nAsistente: {res}\n" for msg, res in history])
14
+ prompt += f"Usuario: {message}\nAsistente:"
15
 
16
  try:
17
+ response = requests.post(API_URL, headers=HEADERS, json={"inputs": prompt})
18
  response.raise_for_status()
19
  output = response.json()
20
 
21
  if isinstance(output, dict) and "error" in output:
22
  return history, f"[ERROR]: {output['error']}"
23
 
24
+ text = output[0].get("generated_text", "[Respuesta vac铆a]")
25
+ reply = text[len(prompt):].strip()
26
+ history.append((message, reply))
27
+ return history, reply
28
 
29
  except Exception as e:
30
  return history, f"[ERROR de conexi贸n]: {str(e)}"
 
46
  msg = gr.Textbox(placeholder="Escribe un mensaje...", label="Mensaje")
47
  send = gr.Button("Enviar")
48
 
49
+ state = gr.State([])
50
 
51
  send.click(fn=chat_with_smart, inputs=[msg, state], outputs=[state, chatbot])
52
  new_chat_btn.click(lambda: ([], None), outputs=[state, chatbot])