Jyothikamalesh commited on
Commit
61abdf6
·
verified ·
1 Parent(s): f9cc39e

Streamlit conversion

Browse files
Files changed (1) hide show
  1. app.py +19 -24
app.py CHANGED
@@ -1,9 +1,13 @@
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/",
@@ -33,7 +37,7 @@ def respond(
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,25 +66,16 @@ def respond(
62
  print(f"Error: {e}")
63
  yield "Error occurred. Please try again."
64
 
65
- chatbot = gr.Chatbot(height=600)
 
66
 
67
- demo = gr.ChatInterface(
68
- respond,
69
- additional_inputs=[
70
- gr.Textbox(value="", label="System message"),
71
- gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
72
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
73
- gr.Slider(
74
- minimum=0.1,
75
- maximum=1.0,
76
- value=0.95,
77
- step=0.05,
78
- label="Top-P",
79
- ),
80
-
81
- ],
82
- fill_height=True,
83
- chatbot=chatbot
84
- )
85
- if __name__ == "__main__":
86
- demo.launch(show_error=True)
 
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("ACCESS_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/",
 
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
  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
+ st.write(response)