dzezzefezfz commited on
Commit
2cf5059
·
verified ·
1 Parent(s): 23836e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import os
4
+
5
+ API_URL = "https://router.huggingface.co/hf-inference/models/mistralai/Mistral-7B-Instruct-v0.2"
6
+ HEADERS = {
7
+ "Authorization": f"Bearer {os.environ['HF_API_KEY']}"
8
+ }
9
+
10
+ def chat(message):
11
+ response = requests.post(
12
+ API_URL,
13
+ headers=HEADERS,
14
+ json={
15
+ "inputs": message,
16
+ "parameters": {
17
+ "max_new_tokens": 200,
18
+ "temperature": 0.7
19
+ }
20
+ },
21
+ timeout=60
22
+ )
23
+
24
+ data = response.json()
25
+ if isinstance(data, list) and "generated_text" in data[0]:
26
+ return data[0]["generated_text"]
27
+
28
+ return str(data)
29
+
30
+ gr.Interface(
31
+ fn=chat,
32
+ inputs=gr.Textbox(label="You"),
33
+ outputs=gr.Textbox(label="Bot"),
34
+ title="My AI Chatbot"
35
+ ).launch()