Spaces:
Sleeping
Sleeping
import gradio as gr | |
import matplotlib.pyplot as plt | |
from transformers import pipeline | |
# Load the Hugging Face pipelines for translation and text generation | |
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es") | |
generator = pipeline("text-generation", model="gpt3.5-turbo") | |
# Define the function to generate the graph based on the translated prompt | |
def generate_graph(prompt): | |
# Translate the prompt to the desired language (e.g., from English to Spanish) | |
translated_prompt = translator(prompt, max_length=100, src_lang="en", tgt_lang="es") | |
translated_text = translated_prompt[0]['translation_text'] | |
# Generate text using the Hugging Face pipeline | |
response = generator(translated_text, max_length=100) | |
text = response[0]['generated_text'] | |
# Generate the graph using Matplotlib | |
# Replace this code with your specific graph generation logic | |
x = [1, 2, 3, 4, 5] | |
y = [2, 4, 6, 8, 10] | |
plt.plot(x, y) | |
plt.xlabel('X') | |
plt.ylabel('Y') | |
plt.title('Generated Graph') | |
# Save the generated graph to a file | |
graph_path = '/path/to/generated_graph.png' | |
plt.savefig(graph_path) | |
return graph_path | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=generate_graph, | |
inputs="text", | |
outputs="file", | |
title="Graph Generator", | |
description="Generate a graph based on a translated prompt", | |
examples=[ | |
["Translate and generate a graph"], | |
["Translate and graph the relationship between X and Y"], | |
] | |
) | |
# Launch the Gradio interface | |
iface.launch() |