Tonic commited on
Commit
27c22a4
·
verified ·
1 Parent(s): 0fc3dbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -43,7 +43,18 @@ def generate_response(system_prompt, user_prompt, max_tokens, temperature):
43
  do_sample=True
44
  )
45
 
46
- return outputs[0]["generated_text"]
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  # Example configurations
49
  examples = [
@@ -88,12 +99,12 @@ with gr.Blocks() as demo:
88
  with gr.Row():
89
  with gr.Column():
90
  system_prompt = gr.Textbox(
91
- label="System Prompt",
92
  placeholder="Enter system prompt...",
93
  value="You are a medieval knight and must provide explanations to modern people."
94
  )
95
  user_prompt = gr.Textbox(
96
- label="User Prompt",
97
  placeholder="Enter your question...",
98
  value="How should I explain the Internet?"
99
  )
@@ -104,21 +115,21 @@ with gr.Blocks() as demo:
104
  maximum=512,
105
  value=128,
106
  step=1,
107
- label="Maximum Tokens"
108
  )
109
  temperature = gr.Slider(
110
  minimum=0.1,
111
  maximum=1.0,
112
  value=0.7,
113
  step=0.1,
114
- label="Temperature"
115
  )
116
 
117
  submit_btn = gr.Button("🚀 Generate Response")
118
 
119
  with gr.Column():
120
  output = gr.Textbox(
121
- label="Generated Response",
122
  lines=10
123
  )
124
 
 
43
  do_sample=True
44
  )
45
 
46
+ # Parse the response to get only the assistant's message
47
+ try:
48
+ response_text = outputs[0]["generated_text"]
49
+ # Find the assistant's content
50
+ assistant_start = response_text.find("'assistant', 'content': '") + len("'assistant', 'content': '")
51
+ assistant_end = response_text.rfind("'}")
52
+ if assistant_start > -1 and assistant_end > -1:
53
+ return response_text[assistant_start:assistant_end]
54
+ else:
55
+ return "Could not parse response properly"
56
+ except Exception as e:
57
+ return f"Error parsing response: {str(e)}"
58
 
59
  # Example configurations
60
  examples = [
 
99
  with gr.Row():
100
  with gr.Column():
101
  system_prompt = gr.Textbox(
102
+ label="🤖Instructions",
103
  placeholder="Enter system prompt...",
104
  value="You are a medieval knight and must provide explanations to modern people."
105
  )
106
  user_prompt = gr.Textbox(
107
+ label="🗣️User Message",
108
  placeholder="Enter your question...",
109
  value="How should I explain the Internet?"
110
  )
 
115
  maximum=512,
116
  value=128,
117
  step=1,
118
+ label="🪙Maximum Tokens"
119
  )
120
  temperature = gr.Slider(
121
  minimum=0.1,
122
  maximum=1.0,
123
  value=0.7,
124
  step=0.1,
125
+ label="🌡️Temperature"
126
  )
127
 
128
  submit_btn = gr.Button("🚀 Generate Response")
129
 
130
  with gr.Column():
131
  output = gr.Textbox(
132
+ label="🤳🏻Phi-4",
133
  lines=10
134
  )
135