Spaces:
Sleeping
Sleeping
Commit
·
1014ac5
1
Parent(s):
59d5415
Add application file
Browse files- app.py +48 -0
- requirements.txt +7 -0
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Load the Hugging Face pipelines for translation and text generation
|
| 6 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
|
| 7 |
+
generator = pipeline("text-generation", model="gpt3.5-turbo")
|
| 8 |
+
|
| 9 |
+
# Define the function to generate the graph based on the translated prompt
|
| 10 |
+
def generate_graph(prompt):
|
| 11 |
+
# Translate the prompt to the desired language (e.g., from English to Spanish)
|
| 12 |
+
translated_prompt = translator(prompt, max_length=100, src_lang="en", tgt_lang="es")
|
| 13 |
+
translated_text = translated_prompt[0]['translation_text']
|
| 14 |
+
|
| 15 |
+
# Generate text using the Hugging Face pipeline
|
| 16 |
+
response = generator(translated_text, max_length=100)
|
| 17 |
+
text = response[0]['generated_text']
|
| 18 |
+
|
| 19 |
+
# Generate the graph using Matplotlib
|
| 20 |
+
# Replace this code with your specific graph generation logic
|
| 21 |
+
x = [1, 2, 3, 4, 5]
|
| 22 |
+
y = [2, 4, 6, 8, 10]
|
| 23 |
+
plt.plot(x, y)
|
| 24 |
+
plt.xlabel('X')
|
| 25 |
+
plt.ylabel('Y')
|
| 26 |
+
plt.title('Generated Graph')
|
| 27 |
+
|
| 28 |
+
# Save the generated graph to a file
|
| 29 |
+
graph_path = '/path/to/generated_graph.png'
|
| 30 |
+
plt.savefig(graph_path)
|
| 31 |
+
|
| 32 |
+
return graph_path
|
| 33 |
+
|
| 34 |
+
# Create the Gradio interface
|
| 35 |
+
iface = gr.Interface(
|
| 36 |
+
fn=generate_graph,
|
| 37 |
+
inputs="text",
|
| 38 |
+
outputs="file",
|
| 39 |
+
title="Graph Generator",
|
| 40 |
+
description="Generate a graph based on a translated prompt",
|
| 41 |
+
examples=[
|
| 42 |
+
["Translate and generate a graph"],
|
| 43 |
+
["Translate and graph the relationship between X and Y"],
|
| 44 |
+
]
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# Launch the Gradio interface
|
| 48 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
matplotlib
|
| 3 |
+
textstat
|
| 4 |
+
transformers
|
| 5 |
+
langdetect
|
| 6 |
+
torch
|
| 7 |
+
tensorflow
|