app.py
Browse files
app.py
CHANGED
|
@@ -1,43 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
# Load the
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
response
|
| 15 |
-
if response.status_code == 200:
|
| 16 |
-
data = response.json()
|
| 17 |
-
return data['bitcoin']['usd']
|
| 18 |
-
return None
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
else:
|
| 29 |
-
return "Error fetching Bitcoin price."
|
| 30 |
|
| 31 |
-
|
| 32 |
-
def crypto_analysis():
|
| 33 |
-
return generate_crypto_insight()
|
| 34 |
-
|
| 35 |
-
# Create Gradio interface
|
| 36 |
-
gr_interface = gr.Interface(fn=crypto_analysis,
|
| 37 |
-
inputs=None,
|
| 38 |
-
outputs="text",
|
| 39 |
-
title="Real-Time Crypto Analysis",
|
| 40 |
-
description="Fetch the current Bitcoin price and get market insights using GPT-Neo.")
|
| 41 |
-
|
| 42 |
-
# Launch the app
|
| 43 |
-
gr_interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Load the smaller model and tokenizer
|
| 5 |
+
model_name = "distilgpt2"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
+
def generate_response(prompt):
|
| 10 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 11 |
+
outputs = model.generate(**inputs, max_length=150, num_return_sequences=1)
|
| 12 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 13 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Set up Gradio interface
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=generate_response,
|
| 18 |
+
inputs="text",
|
| 19 |
+
outputs="text",
|
| 20 |
+
title="Crypto Analysis Model",
|
| 21 |
+
description="Enter your prompt related to Bitcoin or cryptocurrency."
|
| 22 |
+
)
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|