Jyothikamalesh commited on
Commit
47fcff2
·
verified ·
1 Parent(s): 968f1a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -18
app.py CHANGED
@@ -1,14 +1,10 @@
1
- import streamlit as st
2
  from openai import OpenAI, APIError
3
  import os
4
  import tenacity
5
 
6
- # Get the OpenAI API key from the Space settings
7
  ACCESS_TOKEN = os.getenv("HF_TOKEN")
8
 
9
- # Get the model name from the Space settings
10
- MODEL = "NousResearch/Hermes-3-Llama-3.1-8B"
11
-
12
  client = OpenAI(
13
  base_url="https://api-inference.huggingface.co/v1/",
14
  api_key=ACCESS_TOKEN,
@@ -37,7 +33,7 @@ def respond(
37
  response = ""
38
 
39
  for message in client.chat.completions.create(
40
- model=MODEL,
41
  max_tokens=max_tokens,
42
  stream=True,
43
  temperature=temperature,
@@ -66,17 +62,32 @@ def respond(
66
  print(f"Error: {e}")
67
  yield "Error occurred. Please try again."
68
 
69
- st.title("Chatbot")
70
- st.write("Type a message to chat with the bot")
 
71
 
72
- message = st.text_input("Message")
73
- history = []
74
- system_message = st.text_input("System message")
75
- max_tokens = st.slider("Max new tokens", 1, 2048, 2048)
76
- temperature = st.slider("Temperature", 0.1, 4.0, 0.7)
77
- top_p = st.slider("Top-P", 0.1, 1.0, 0.95)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- if st.button("Send"):
80
- response = respond(message, history, system_message, max_tokens, temperature, top_p)
81
- for resp in response:
82
- st.write(resp)
 
1
+ import gradio as gr
2
  from openai import OpenAI, APIError
3
  import os
4
  import tenacity
5
 
 
6
  ACCESS_TOKEN = os.getenv("HF_TOKEN")
7
 
 
 
 
8
  client = OpenAI(
9
  base_url="https://api-inference.huggingface.co/v1/",
10
  api_key=ACCESS_TOKEN,
 
33
  response = ""
34
 
35
  for message in client.chat.completions.create(
36
+ model="NousResearch/Hermes-3-Llama-3.1-8B",
37
  max_tokens=max_tokens,
38
  stream=True,
39
  temperature=temperature,
 
62
  print(f"Error: {e}")
63
  yield "Error occurred. Please try again."
64
 
65
+ def launch_app():
66
+ try:
67
+ chatbot = gr.Chatbot(height=600)
68
 
69
+ demo = gr.ChatInterface(
70
+ respond,
71
+ additional_inputs=[
72
+ gr.Textbox(value="", label="System message"),
73
+ gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
74
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
75
+ gr.Slider(
76
+ minimum=0.1,
77
+ maximum=1.0,
78
+ value=0.95,
79
+ step=0.05,
80
+ label="Top-P",
81
+ ),
82
+
83
+ ],
84
+ fill_height=True,
85
+ chatbot=chatbot
86
+ )
87
+ demo.launch(show_error=True)
88
+ except KeyError as e:
89
+ print(f"Error: {e}")
90
+ print("Please try again.")
91
 
92
+ if __name__ == "__main__":
93
+ launch_app()