rishikasharma commited on
Commit
2973c99
·
verified ·
1 Parent(s): f113451

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -1,7 +1,37 @@
1
- from huggingface_hub import InferenceClient
 
 
 
2
 
3
- client = InferenceClient(
4
- model="mistralai/Mistral-7B-Instruct-v0.3",
5
- token="your_actual_token_here" # Replace with the actual token temporarily
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  )
7
- print(client.text_generation(prompt="Hello"))
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ from dotenv import load_dotenv
4
+ import os
5
 
6
+ load_dotenv()
7
+ HUGGINGFACE_TOKEN = os.getenv('HUGGINGFACE_TOKEN')
8
+
9
+ # Hugging Face API configuration
10
+ API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
11
+ HEADERS = {"Authorization": f"Bearer {HUGGINGFACE_TOKEN}"}
12
+
13
+ # Function to interact with the Hugging Face model
14
+ def query_huggingface_api(input_text):
15
+ payload = {"inputs": input_text}
16
+ try:
17
+ response = requests.post(API_URL, headers=HEADERS, json=payload)
18
+ response.raise_for_status() # Raise error for HTTP errors
19
+ return response.json()[0]["generated_text"]
20
+ except requests.exceptions.RequestException as e:
21
+ return f"Error: {str(e)}"
22
+
23
+ # Gradio interface
24
+ def chatbot(input_text):
25
+ response = query_huggingface_api(input_text)
26
+ return response
27
+
28
+ iface = gr.Interface(
29
+ fn=chatbot,
30
+ inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
31
+ outputs=gr.Textbox(),
32
+ title="AI Chatbot",
33
+ description="Chat with the AI powered by Hugging Face Mistral-7B-Instruct-v0.3.",
34
  )
35
+
36
+ if __name__ == "__main__":
37
+ iface.launch()