Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,59 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
if __name__ == "__main__":
|
| 64 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
# Chatbot using GPT model
|
| 6 |
+
chatbot = pipeline("text-generation", model="gpt2")
|
| 7 |
+
|
| 8 |
+
def chatbot_response(query):
|
| 9 |
+
response = chatbot(query, max_length=50)
|
| 10 |
+
return response[0]['generated_text']
|
| 11 |
+
|
| 12 |
+
# Image Generator using Stable Diffusion
|
| 13 |
+
image_generator = pipeline("text-to-image", model="CompVis/stable-diffusion-v1-4")
|
| 14 |
+
|
| 15 |
+
def generate_image(prompt):
|
| 16 |
+
return image_generator(prompt)[0]['image']
|
| 17 |
+
|
| 18 |
+
# Code Generator (Simple example for Arduino)
|
| 19 |
+
def generate_code(prompt):
|
| 20 |
+
if "arduino" in prompt.lower():
|
| 21 |
+
return '''
|
| 22 |
+
void setup() {
|
| 23 |
+
pinMode(LED_BUILTIN, OUTPUT);
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
void loop() {
|
| 27 |
+
digitalWrite(LED_BUILTIN, HIGH);
|
| 28 |
+
delay(1000);
|
| 29 |
+
digitalWrite(LED_BUILTIN, LOW);
|
| 30 |
+
delay(1000);
|
| 31 |
+
}
|
| 32 |
+
'''
|
| 33 |
+
return "Sorry, I don't have a code for this request."
|
| 34 |
+
|
| 35 |
+
# Research Bot using OpenAI
|
| 36 |
+
def research_bot(query):
|
| 37 |
+
openai.api_key = "YOUR_OPENAI_API_KEY"
|
| 38 |
+
response = openai.Completion.create(
|
| 39 |
+
engine="text-davinci-003",
|
| 40 |
+
prompt=query,
|
| 41 |
+
max_tokens=100
|
| 42 |
+
)
|
| 43 |
+
return response.choices[0].text.strip()
|
| 44 |
+
|
| 45 |
+
# Logo Generator (Using a simple placeholder)
|
| 46 |
+
def generate_logo(prompt):
|
| 47 |
+
return f"Logo for '{prompt}' is being generated..."
|
| 48 |
+
|
| 49 |
+
# Create Gradio Interface
|
| 50 |
+
iface = gr.Interface(
|
| 51 |
+
fn=[chatbot_response, generate_image, generate_code, research_bot, generate_logo],
|
| 52 |
+
inputs=["text", "text", "text", "text", "text"],
|
| 53 |
+
outputs=["text", "image", "text", "text", "text"],
|
| 54 |
+
live=True,
|
| 55 |
+
title="Nithin AI - All-in-One Tool",
|
| 56 |
+
description="Your one-stop solution for AI-generated images, code, chat, research, and logos."
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
+
iface.launch(share=True)
|
|
|
|
|
|