Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,23 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
# if not HF_TOKEN:
|
10 |
-
# raise ValueError("The HF environment variable is not set. Please set it to your Hugging Face token.")
|
11 |
-
|
12 |
-
# # Authenticate with Hugging Face and save the token to the Git credentials helper
|
13 |
-
# login(HF_TOKEN, add_to_git_credential=True)
|
14 |
-
|
15 |
-
# Create the pipeline for text generation using the specified model
|
16 |
-
# pipe = pipeline("text-generation", model="distilbert/distilgpt2", token=HF_TOKEN)
|
17 |
-
pipe = pipeline("text-generation", model="openai-community/gpt2-medium")
|
18 |
|
19 |
# Define the initial prompt for the system
|
20 |
system_prompt = """
|
21 |
You are an AI model designed to provide concise information about big data analytics across various fields without mentioning the question. Respond with a focused, one-line answer that captures the essence of the key risk, benefit, or trend associated with the topic.
|
22 |
-
|
23 |
input: What do you consider the most significant risk of over-reliance on big data analytics in stock market risk management?
|
24 |
output: Increased market volatility.
|
25 |
-
|
26 |
input: What is a major benefit of big data analytics in healthcare?
|
27 |
output: Enhanced patient care through personalized treatment.
|
28 |
-
|
29 |
input: What is a key challenge of big data analytics in retail?
|
30 |
output: Maintaining data privacy and security.
|
31 |
-
|
32 |
input: What is a primary advantage of big data analytics in manufacturing?
|
33 |
output: Improved production efficiency and predictive maintenance.
|
34 |
-
|
35 |
input: What is a significant risk associated with big data analytics in education?
|
36 |
output: Potential widening of the achievement gap if data is not used equitably.
|
37 |
"""
|
@@ -41,9 +27,14 @@ def generate(text):
|
|
41 |
# Combine the system prompt with the user's input
|
42 |
prompt = system_prompt + f"\ninput: {text}\noutput:"
|
43 |
|
44 |
-
#
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
return response_text if response_text else "No valid response generated."
|
49 |
|
@@ -63,4 +54,4 @@ def launch_custom_interface():
|
|
63 |
iface.launch()
|
64 |
|
65 |
if __name__ == "__main__":
|
66 |
-
launch_custom_interface()
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
5 |
|
6 |
+
# Load the model and tokenizer
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("openai-community/gpt2-medium")
|
8 |
+
model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2-medium")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Define the initial prompt for the system
|
11 |
system_prompt = """
|
12 |
You are an AI model designed to provide concise information about big data analytics across various fields without mentioning the question. Respond with a focused, one-line answer that captures the essence of the key risk, benefit, or trend associated with the topic.
|
|
|
13 |
input: What do you consider the most significant risk of over-reliance on big data analytics in stock market risk management?
|
14 |
output: Increased market volatility.
|
|
|
15 |
input: What is a major benefit of big data analytics in healthcare?
|
16 |
output: Enhanced patient care through personalized treatment.
|
|
|
17 |
input: What is a key challenge of big data analytics in retail?
|
18 |
output: Maintaining data privacy and security.
|
|
|
19 |
input: What is a primary advantage of big data analytics in manufacturing?
|
20 |
output: Improved production efficiency and predictive maintenance.
|
|
|
21 |
input: What is a significant risk associated with big data analytics in education?
|
22 |
output: Potential widening of the achievement gap if data is not used equitably.
|
23 |
"""
|
|
|
27 |
# Combine the system prompt with the user's input
|
28 |
prompt = system_prompt + f"\ninput: {text}\noutput:"
|
29 |
|
30 |
+
# Tokenize the input
|
31 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
32 |
+
|
33 |
+
# Generate the response
|
34 |
+
outputs = model.generate(inputs["input_ids"], max_length=256)
|
35 |
+
|
36 |
+
# Convert the output to text
|
37 |
+
response_text = tokenizer.decode(outputs[0], skip_special_tokens=True).split("output:")[-1].strip()
|
38 |
|
39 |
return response_text if response_text else "No valid response generated."
|
40 |
|
|
|
54 |
iface.launch()
|
55 |
|
56 |
if __name__ == "__main__":
|
57 |
+
launch_custom_interface()
|