Myloiose commited on
Commit
3d1908c
·
verified ·
1 Parent(s): 37af6b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -15
app.py CHANGED
@@ -2,31 +2,33 @@ import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
- # ⚠️ Ahora el token vendrá desde los "Secrets" del Space
6
  HF_TOKEN = os.getenv("HF_TOKEN")
7
 
8
- client = InferenceClient(
9
- model="mistralai/Mistral-7B-Instruct-v0.3",
10
- token=HF_TOKEN
11
- )
12
 
13
- def chat(message, history):
14
  try:
15
  response = client.text_generation(
16
  prompt=message,
17
  max_new_tokens=200,
18
- temperature=0.7
 
19
  )
20
- history.append((message, response))
21
- return "", history
22
  except Exception as e:
23
- history.append(("⚠️ Error interno", str(e)))
24
- return "", history
25
 
26
- demo = gr.ChatInterface(
27
- fn=chat,
 
 
28
  title="💬 Mistral Replica Chat",
29
- description="Chat con el modelo Mistral 7B Instruct vía Hugging Face",
30
  )
31
 
32
- demo.launch()
 
 
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
+ # Lee el token desde los secretos de tu Space (Settings → Repository secrets → HF_TOKEN)
6
  HF_TOKEN = os.getenv("HF_TOKEN")
7
 
8
+ # Modelo base (usa Mistral oficial)
9
+ MODEL = "mistralai/Mistral-7B-Instruct-v0.3"
10
+
11
+ client = InferenceClient(model=MODEL, token=HF_TOKEN)
12
 
13
+ def chat_with_mistral(message):
14
  try:
15
  response = client.text_generation(
16
  prompt=message,
17
  max_new_tokens=200,
18
+ temperature=0.7,
19
+ repetition_penalty=1.1,
20
  )
21
+ return response
 
22
  except Exception as e:
23
+ return f"⚠️ Error: {str(e)}"
 
24
 
25
+ iface = gr.Interface(
26
+ fn=chat_with_mistral,
27
+ inputs="text",
28
+ outputs="text",
29
  title="💬 Mistral Replica Chat",
30
+ description="Chat de prueba usando el modelo Mistral desde Hugging Face API",
31
  )
32
 
33
+ if __name__ == "__main__":
34
+ iface.launch()