TejAndrewsACC commited on
Commit
98a1e78
·
verified ·
1 Parent(s): 1e2268c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -56
app.py CHANGED
@@ -1,59 +1,11 @@
1
  import gradio as gr
2
- import requests
3
 
4
- # Define the API settings
5
- API_TOKEN = "YOUR_HUGGING_FACE_API_TOKEN" # Replace with your HF token
6
- MODEL_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-3.3-70B-Instruct"
 
 
7
 
8
- # Function to fetch a response from the model
9
- def chat_with_model(user_input):
10
- headers = {
11
- "Authorization": f"Bearer {API_TOKEN}",
12
- "Content-Type": "application/json",
13
- }
14
- payload = {
15
- "inputs": user_input,
16
- "parameters": {
17
- "max_length": 100,
18
- "temperature": 0.7,
19
- "top_k": 50,
20
- },
21
- "options": {"wait_for_model": True},
22
- }
23
-
24
- response = requests.post(MODEL_URL, headers=headers, json=payload)
25
-
26
- if response.status_code == 200:
27
- result = response.json()
28
- if result and isinstance(result, list):
29
- return result[0].get("generated_text", "No response received.")
30
- else:
31
- return f"Error {response.status_code}: {response.text}"
32
-
33
- return "An error occurred while generating a response."
34
-
35
- # Gradio Interface
36
- def chatbot(user_message):
37
- # Add a system message for context
38
- system_message = "You are a helpful assistant using the Llama-3.3-70B model. Respond thoughtfully."
39
- full_input = f"{system_message}\nUser: {user_message}\nAssistant:"
40
- return chat_with_model(full_input)
41
-
42
- # Load your HTML UI
43
- with open("index.html", "r") as html_file:
44
- custom_html = html_file.read()
45
-
46
- # Gradio App with Custom HTML
47
- app = gr.Interface(
48
- fn=chatbot,
49
- inputs="text",
50
- outputs="text",
51
- title="Chatbot with Llama-3.3-70B",
52
- )
53
-
54
- # Add the HTML to the app
55
- app.launch(
56
- inline=True, # Embed the app into the HTML
57
- share=True, # Make the app shareable
58
- custom_html=custom_html, # Use the custom HTML file
59
- )
 
1
  import gradio as gr
 
2
 
3
+ # Function to serve the HTML content
4
+ def display_html():
5
+ with open("index.html", "r") as file:
6
+ html_content = file.read()
7
+ return html_content
8
 
9
+ # Gradio interface with custom HTML rendering
10
+ interface = gr.Interface(
11
+ fn=display_html,