AngeT10 commited on
Commit
8ac4e72
1 Parent(s): 8d039fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -92
app.py CHANGED
@@ -1,99 +1,44 @@
1
  import gradio as gr
2
- import sqlite3
3
  import torch
4
  import os
5
  import zipfile
6
  import requests
7
  from TTS.api import TTS
8
 
9
- # Create a database connection
10
- conn = sqlite3.connect("shared_models.db")
11
- cursor = conn.cursor()
12
-
13
- # Create a table to store shared models
14
- cursor.execute("""
15
- CREATE TABLE IF NOT EXISTS shared_models (
16
- id INTEGER PRIMARY KEY,
17
- model_url TEXT,
18
- model_name TEXT
19
- );
20
- """)
21
-
22
- # Define a function to store a shared model
23
- def store_shared_model(model_url, model_name):
24
- cursor.execute("INSERT INTO shared_models (model_url, model_name) VALUES (?,?)", (model_url, model_name))
25
- conn.commit()
26
-
27
- # Modify the get_shared_models function to display shared models
28
- def get_shared_models():
29
- cursor.execute("SELECT * FROM shared_models")
30
- models = cursor.fetchall()
31
- community_links.update(value="\n".join([f"{model[1]} ({model[0]})" for model in models]))
32
- return models
33
-
34
- # Define a function to clone a model
35
- def clone(text, url, language):
36
- # Store the shared model in the database
37
- store_shared_model(url, text)
38
- # Call the original clone function
39
- return original_clone(text, url, language)
40
-
41
- # Get the original clone function
42
- original_clone = clone
43
-
44
- # Modify the Textbox component to store shared models
45
- community_links = gr.components.Textbox(label="Community Links/Models")
46
-
47
- # Define a button to share a model
48
- share_button = gr.components.Button("Share Model")
49
-
50
- # Define a dropdown menu to retrieve shared models
51
- shared_models = get_shared_models()
52
- model_dropdown = gr.components.Dropdown(choices=[], label="Shared Models")
53
-
54
- # Define the clone function
55
- def clone_with_dropdown(text, url, language, model_id):
56
- # Retrieve the shared model from the database
57
- cursor.execute("SELECT * FROM shared_models WHERE id=?", (model_id,))
58
- model = cursor.fetchone()
59
- if model:
60
- # Call the clone function with the shared model URL
61
- return clone(text, model[1], language)
62
- else:
63
- # Call the original clone function
64
- return original_clone(text, url, language)
65
-
66
- # Update the interface
67
- iface = gr.Interface(fn=clone_with_dropdown,
68
- inputs=[
69
- gr.components.Text("", label="the text to be said"),
70
- gr.components.Text("", label="URL of the zip file with the dataset on hf.co (10 seconds is fine)"),
71
- gr.Dropdown(choices=languages, label="Language"),
72
- community_links,
73
- share_button,
74
- model_dropdown
75
- ],
76
- outputs=gr.Audio(type='filepath'),
77
- title='Voice Clone',
78
- description="""
79
- by [Angetyde](https://youtube.com/@Angetyde?si=7nusP31nTumIkPTF) and [Tony Assi](https://www.tonyassi.com/ )
80
- use this colab with caution <3.
81
- """,
82
- theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate"))
83
-
84
- # Define a function to handle the share button click event
85
- def handle_share_button(text, url, language):
86
- # Split the text into model name and URL
87
- model_name, model_url = text.split(",")
88
- # Store the shared model in the database
89
- store_shared_model(model_url, model_name)
90
- # Update the shared models list
91
- shared_models = get_shared_models()
92
- model_dropdown.update(choices=[(model[1], model[0]) for model in shared_models])
93
- # Clear the textbox
94
- community_links.update(value="")
95
-
96
- # Connect the share button to the handle_share_button function
97
- share_button.click(fn=handle_share_button, inputs=[community_links])
98
-
99
- iface.launch(share=True, on_launch=get_shared_models)
 
1
  import gradio as gr
 
2
  import torch
3
  import os
4
  import zipfile
5
  import requests
6
  from TTS.api import TTS
7
 
8
+ #... (rest of the code remains the same)
9
+
10
+ # Add a new section for model sharing
11
+ model_sharing_section = gr.components.Section("Model Sharing")
12
+
13
+ model_input = gr.components.Textbox(label="Share your model/link")
14
+ model_output = gr.components.Markdown(label="Shared Models")
15
+
16
+ model_sharing_iface = gr.Interface(
17
+ fn=lambda x: x, # dummy function to display the input
18
+ inputs=model_input,
19
+ outputs=model_output,
20
+ title="Share Your Model",
21
+ description="Share your model or link with the community!"
22
+ )
23
+
24
+ # Combine the two interfaces
25
+ iface = gr.Interface(
26
+ fn=clone,
27
+ inputs=[
28
+ gr.components.Text("", label="the text to be said"),
29
+ gr.components.Text("", label="URL of the zip file with the dataset on hf.co (10 seconds is fine)"),
30
+ gr.Dropdown(choices=languages, label="Language")
31
+ ],
32
+ outputs=gr.Audio(type='filepath'),
33
+ title='Voice Clone',
34
+ description="""
35
+ by [Angetyde](https://youtube.com/@Angetyde?si=7nusP31nTumIkPTF) and [Tony Assi](https://www.tonyassi.com/ )
36
+ use this colab with caution <3.
37
+ """,
38
+ theme=gr.themes.Base(primary_hue="teal", secondary_hue="teal", neutral_hue="slate"),
39
+ tabs=["Voice Clone", "Model Sharing"]
40
+ )
41
+
42
+ iface.add_component(model_sharing_iface, "Model Sharing")
43
+
44
+ iface.launch(share=True)