typesdigital commited on
Commit
9991862
·
1 Parent(s): 93ad901

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -1,21 +1,22 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Create a text generation pipeline using Hugging Face Transformers
5
- generator = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
6
 
7
- # Define the chat function
8
- def chat(input_text):
9
- response = generator(input_text, max_length=50, do_sample=True)[0]["generated_text"]
10
- return response
11
 
12
- # Create a Gradio interface
13
  iface = gr.Interface(
14
- fn=chat,
15
- inputs=gr.inputs.Textbox(label="Input Text"),
16
- outputs=gr.outputs.Textbox(label="Response"),
 
 
17
  live=True,
 
18
  )
19
 
20
- # Launch the Gradio interface
21
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Replace 'your_openai_api_key' with your actual OpenAI API key
5
+ api_key = "your_openai_api_key"
6
 
7
+ def generate_response(text):
8
+ generator = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B", device=0) # You can choose a different model here
9
+ response = generator(text, max_length=150, num_return_sequences=1, api_key=api_key)
10
+ return response[0]['generated_text']
11
 
 
12
  iface = gr.Interface(
13
+ fn=generate_response,
14
+ inputs="text",
15
+ outputs="text",
16
+ title="GPT-3.5 Turbo Chat",
17
+ description="An interface to chat with GPT-3.5 Turbo.",
18
  live=True,
19
+ theme="huggingface",
20
  )
21
 
 
22
  iface.launch()