braxtongough commited on
Commit
1e3060e
·
verified ·
1 Parent(s): ad9da17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -22
app.py CHANGED
@@ -1,35 +1,25 @@
1
- import openai
2
  import gradio as gr
 
3
 
4
- # Set up OpenAI API key
5
- openai.api_key = 'your_openai_api_key_here' # Replace with your OpenAI API key
6
 
7
- # Function to generate code based on user input
8
  def generate_code(input_text):
9
  try:
10
- # Use GPT-3 to generate code
11
- response = openai.Completion.create(
12
- engine="text-davinci-003",
13
- prompt=f"Generate a code based on the following request: {input_text}",
14
- max_tokens=150,
15
- n=1,
16
- stop=None,
17
- temperature=0.7
18
- )
19
- # Extract the response text
20
- code = response.choices[0].text.strip()
21
- return code
22
  except Exception as e:
23
  return f"Error: {str(e)}"
24
 
25
- # Gradio Interface setup
26
  iface = gr.Interface(
27
  fn=generate_code, # Function to call
28
- inputs="text", # User input type (text input box)
29
- outputs="text", # Output type (text box for the generated code)
30
- title="HandyAI - Your All Purpose AI", # Title of the app
31
- description="HandyAI generates code based on your request. Simply describe what you want, and it will generate code for you.", # Description
32
- theme="compact", # Interface theme (compact, default, etc.)
33
  )
34
 
35
  # Launch the interface
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Load your model from Hugging Face (for text generation)
5
+ model = pipeline('text-generation', model='gpt2') # Replace with the model you want
6
 
7
+ # Function to generate code (or text) based on user input
8
  def generate_code(input_text):
9
  try:
10
+ # Generate the output text based on input
11
+ output = model(input_text, max_length=150, num_return_sequences=1)[0]['generated_text']
12
+ return output
 
 
 
 
 
 
 
 
 
13
  except Exception as e:
14
  return f"Error: {str(e)}"
15
 
16
+ # Gradio interface
17
  iface = gr.Interface(
18
  fn=generate_code, # Function to call
19
+ inputs="text", # Text input field for user to enter requests
20
+ outputs="text", # Text output for generated code or text
21
+ title="HandyAI - Your All Purpose AI",
22
+ description="HandyAI can generate code or text based on your input request."
 
23
  )
24
 
25
  # Launch the interface