Web3Daily commited on
Commit
9419609
1 Parent(s): 027f076

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -7
app.py CHANGED
@@ -1,15 +1,31 @@
 
1
  import gradio as gr
2
- from transformers import pipeline
 
 
 
3
 
4
  def chat_with_gpt(input_text):
5
- model_name = "gpt2-large" # Replace this with the appropriate GPT model you want to use.
6
- chat_gpt = pipeline("text-generation", model=model_name, device=0)
7
- generated_text = chat_gpt(input_text, max_length=150, do_sample=True, top_k=50, top_p=0.95)
8
- return generated_text[0]["generated_text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Gradio user interface
11
  input_text = gr.inputs.Textbox(lines=5, label="Your question about AI:")
12
  output_text = gr.outputs.Textbox(label="ChatGPT Response:")
13
 
14
- iface = gr.Interface(fn=chat_with_gpt, inputs=input_text, outputs=output_text, title="Chat with ChatGPT", description="Ask ChatGPT questions about AI.")
15
- iface.launch()
 
1
+ import os
2
  import gradio as gr
3
+ import openai
4
+
5
+ # Set up OpenAI API
6
+ openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
  def chat_with_gpt(input_text):
9
+ model_engine = "text-davinci-002" # Choose the appropriate model engine.
10
+ prompt = f"{input_text} (AI):"
11
+
12
+ response = openai.Completion.create(
13
+ engine=model_engine,
14
+ prompt=prompt,
15
+ max_tokens=100,
16
+ n=1,
17
+ stop=None,
18
+ temperature=0.8,
19
+ top_p=1,
20
+ frequency_penalty=0,
21
+ presence_penalty=0
22
+ )
23
+
24
+ generated_text = response.choices[0].text.strip()
25
+ return generated_text
26
 
27
  # Gradio user interface
28
  input_text = gr.inputs.Textbox(lines=5, label="Your question about AI:")
29
  output_text = gr.outputs.Textbox(label="ChatGPT Response:")
30
 
31
+ iface = gr.Interface(fn=chat_with_gpt)