rioanggara commited on
Commit
5bfd5e8
·
1 Parent(s): c02e1f0
Files changed (2) hide show
  1. app.py +54 -45
  2. requirements.txt +4 -5
app.py CHANGED
@@ -1,50 +1,59 @@
1
  import gradio as gr
 
 
 
2
  import matplotlib.pyplot as plt
3
- from transformers import pipeline
4
-
5
- # Load the Hugging Face pipeline for translation
6
- translator = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")
7
-
8
- # Load the Hugging Face pipeline for text generation using GPT-J
9
- generator = pipeline("text-generation", model="EleutherAI/gpt-j-6B")
10
-
11
- # Define the function to generate the graph based on the translated prompt
12
- def generate_graph(prompt):
13
- # Translate the prompt to the desired language (e.g., from English to Spanish)
14
- translated_prompt = translator(prompt, max_length=100, src_lang="en", tgt_lang="es")
15
- translated_text = translated_prompt[0]['translation_text']
16
-
17
- # Generate text using the Hugging Face pipeline with GPT-J
18
- response = generator(translated_text, max_length=100)
19
- text = response[0]['generated_text']
20
-
21
- # Generate the graph using Matplotlib
22
- # Replace this code with your specific graph generation logic
23
- x = [1, 2, 3, 4, 5]
24
- y = [2, 4, 6, 8, 10]
25
- plt.plot(x, y)
26
- plt.xlabel('X')
27
- plt.ylabel('Y')
28
- plt.title('Generated Graph')
29
-
30
- # Save the generated graph to a file
31
- graph_path = '/path/to/generated_graph.png'
32
- plt.savefig(graph_path)
33
-
34
- return graph_path
35
-
36
- # Create the Gradio interface
 
 
37
  iface = gr.Interface(
38
- fn=generate_graph,
39
- inputs="text",
40
- outputs="file",
41
- title="Graph Generator",
42
- description="Generate a graph based on a translated prompt",
43
- examples=[
44
- ["Translate and generate a graph"],
45
- ["Translate and graph the relationship between X and Y"],
46
- ]
 
 
 
47
  )
48
 
49
- # Launch the Gradio interface
50
- iface.launch()
 
 
1
  import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.linear_model import LinearRegression
5
  import matplotlib.pyplot as plt
6
+ import io
7
+
8
+ def linear_regression(input_csv, x_column, y_column):
9
+ # Load dataset
10
+ df = pd.read_csv(input_csv)
11
+
12
+ # Prepare data for regression
13
+ X = df[[x_column]].values
14
+ y = df[y_column].values
15
+
16
+ # Perform linear regression
17
+ model = LinearRegression()
18
+ model.fit(X, y)
19
+
20
+ # Make predictions
21
+ y_pred = model.predict(X)
22
+
23
+ # Plotting
24
+ plt.figure(figsize=(10, 6))
25
+ plt.scatter(X, y, color='blue')
26
+ plt.plot(X, y_pred, color='red')
27
+ plt.xlabel(x_column)
28
+ plt.ylabel(y_column)
29
+ plt.title('Linear Regression')
30
+
31
+ # Save plot to a buffer
32
+ buf = io.BytesIO()
33
+ plt.savefig(buf, format='png')
34
+ buf.seek(0)
35
+
36
+ # Regression info
37
+ coef_info = f"Coefficient: {model.coef_[0]}\nIntercept: {model.intercept_}"
38
+
39
+ return buf, coef_info
40
+
41
+ # Gradio interface
42
  iface = gr.Interface(
43
+ fn=linear_regression,
44
+ inputs=[
45
+ gr.inputs.File(type="csv"),
46
+ gr.inputs.Textbox(label="X Column Name"),
47
+ gr.inputs.Textbox(label="Y Column Name"),
48
+ ],
49
+ outputs=[
50
+ gr.outputs.Image(type="plot"),
51
+ gr.outputs.Textbox(label="Regression Info")
52
+ ],
53
+ title="Automatic Linear Regression Modeling",
54
+ description="Upload a CSV file and specify the columns for performing linear regression."
55
  )
56
 
57
+ # Launch the app
58
+ if __name__ == "__main__":
59
+ iface.launch()
requirements.txt CHANGED
@@ -1,6 +1,5 @@
1
  gradio
2
- matplotlib
3
- transformers
4
- pytorch
5
- tensorflow
6
- torch
 
1
  gradio
2
+ pandas
3
+ numpy
4
+ scikit-learn
5
+ matplotlib