Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,25 @@
|
|
| 1 |
-
import openai
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
-
# Function to generate code based on user input
|
| 8 |
def generate_code(input_text):
|
| 9 |
try:
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 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
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=generate_code, # Function to call
|
| 28 |
-
inputs="text", #
|
| 29 |
-
outputs="text", #
|
| 30 |
-
title="HandyAI - Your All Purpose AI",
|
| 31 |
-
description="HandyAI
|
| 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
|