akazmi commited on
Commit
47fa0b9
·
verified ·
1 Parent(s): 3b42bd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -1,25 +1,33 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
- # Replace these with your desired model and tokenizer names
5
- model_name = "t5-small"
6
- tokenizer_name = "t5-small"
7
-
8
- tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
9
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
10
 
11
  def generate_response(message):
12
- input_ids = tokenizer(message, return_tensors="pt").input_ids
13
- outputs = model.generate(input_ids)
14
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
 
 
 
 
 
 
 
 
 
 
15
 
 
16
  iface = gr.Interface(
17
  fn=generate_response,
18
  inputs=gr.Textbox(placeholder="Type your message here...", label="Message"),
19
  outputs="text",
20
- title="Real-Time Chatbot with Hugging Face Transformers",
21
- description="Ask any question or start a conversation.",
22
- theme="dark", # Optional: Use a dark theme
23
  )
24
 
25
- iface.launch(debug=True) # Set debug=True for detailed logging during development
 
 
1
  import gradio as gr
2
+ import openai
3
 
4
+ # Set your OpenAI API key here
5
+ openai.api_key = "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" # Replace with your actual API key
 
 
 
 
6
 
7
  def generate_response(message):
8
+ try:
9
+ response = openai.Completion.create(
10
+ engine="text-davinci-003", # Adjust model as needed
11
+ prompt=f"Question: {message}",
12
+ max_tokens=150,
13
+ n=1,
14
+ stop=None, # No explicit stop sequences for chat-like interactions
15
+ temperature=0.7,
16
+ )
17
+ # Return the content of the response
18
+ return response.choices[0].text.strip()
19
+ except Exception as e:
20
+ return f"Error: {str(e)}"
21
 
22
+ # Create the Gradio interface
23
  iface = gr.Interface(
24
  fn=generate_response,
25
  inputs=gr.Textbox(placeholder="Type your message here...", label="Message"),
26
  outputs="text",
27
+ title="Real-Time Chatbot with GPT-3.5",
28
+ description="Ask any question or start a conversation. Powered by OpenAI GPT-3.5-turbo.",
29
+ theme="dark", # Optional: Use a dark theme for a more modern look
30
  )
31
 
32
+ # Launch the interface
33
+ iface.launch()