AK97GAMERZ commited on
Commit
8bc147a
·
verified ·
1 Parent(s): 2eb52ab

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import os
4
+
5
+ # Set your Hugging Face API key
6
+ API_KEY = os.getenv("HF_API_KEY")
7
+
8
+ # Hugging Face Model Endpoint (Change to your preferred LLM)
9
+ MODEL_NAME = "mistralai/Mistral-7B-Instruct"
10
+
11
+ # Function to get response from Hugging Face LLM
12
+ def chat_with_llm(prompt):
13
+ headers = {"Authorization": f"Bearer {API_KEY}"}
14
+ payload = {"inputs": prompt}
15
+ response = requests.post(
16
+ f"https://api-inference.huggingface.co/models/{MODEL_NAME}",
17
+ headers=headers,
18
+ json=payload
19
+ )
20
+ return response.json()[0]["generated_text"]
21
+
22
+ # Create Gradio Chat UI
23
+ iface = gr.Interface(
24
+ fn=chat_with_llm,
25
+ inputs=gr.Textbox(label="Ask me anything"),
26
+ outputs=gr.Textbox(label="AI Response"),
27
+ title="AI Chatbot with Hugging Face API",
28
+ description="A free AI chatbot using Hugging Face's API. Supports multiple LLMs!",
29
+ )
30
+
31
+ # Launch App
32
+ iface.launch()