Spaces:
Sleeping
Sleeping
created an app
Browse files
app.py
CHANGED
@@ -1,37 +1,38 @@
|
|
1 |
-
import
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
# Clear existing objects
|
6 |
-
bpy.ops.object.select_all(action='SELECT')
|
7 |
-
bpy.ops.object.delete()
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
camera = bpy.context.active_object
|
12 |
-
camera.rotation_euler = (1.109, 0, 0)
|
13 |
-
|
14 |
-
# Set the camera as active
|
15 |
-
bpy.context.scene.camera = camera
|
16 |
-
|
17 |
-
# Add a light source
|
18 |
-
bpy.ops.object.light_add(type='POINT', location=(0, 0, 5))
|
19 |
|
20 |
-
|
21 |
-
bpy.ops.mesh.primitive_cube_add(location=(0, 0, 0))
|
22 |
-
cube = bpy.context.active_object
|
23 |
-
cube.name = 'Cube'
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Title of the app
|
5 |
+
st.title("Hugging Face Transformers with Streamlit")
|
|
|
|
|
|
|
6 |
|
7 |
+
# Sidebar for selecting model
|
8 |
+
st.sidebar.header("Select a Model")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
model_option = st.sidebar.radio("Choose a task", ["Text Generation", "Text Summarization", "Sentiment Analysis"])
|
|
|
|
|
|
|
11 |
|
12 |
+
# Load the transformer model based on selected task
|
13 |
+
if model_option == "Text Generation":
|
14 |
+
st.header("Text Generation")
|
15 |
+
model = pipeline("text-generation", model="gpt2")
|
16 |
+
user_input = st.text_area("Enter your prompt:", "Once upon a time")
|
17 |
|
18 |
+
if st.button("Generate Text"):
|
19 |
+
result = model(user_input, max_length=100, num_return_sequences=1)
|
20 |
+
st.write(result[0]["generated_text"])
|
21 |
|
22 |
+
elif model_option == "Text Summarization":
|
23 |
+
st.header("Text Summarization")
|
24 |
+
model = pipeline("summarization", model="facebook/bart-large-cnn")
|
25 |
+
user_input = st.text_area("Enter the text to summarize:", "The quick brown fox jumps over the lazy dog.")
|
26 |
+
|
27 |
+
if st.button("Summarize Text"):
|
28 |
+
result = model(user_input, min_length=25, max_length=100, length_penalty=2.0, num_beams=4, early_stopping=True)
|
29 |
+
st.write(result[0]["summary_text"])
|
30 |
|
31 |
+
elif model_option == "Sentiment Analysis":
|
32 |
+
st.header("Sentiment Analysis")
|
33 |
+
model = pipeline("sentiment-analysis")
|
34 |
+
user_input = st.text_area("Enter the text to analyze:", "I love programming!")
|
35 |
+
|
36 |
+
if st.button("Analyze Sentiment"):
|
37 |
+
result = model(user_input)
|
38 |
+
st.write(f"Sentiment: {result[0]['label']}, Confidence: {result[0]['score']:.2f}")
|